Skip to main content
Version: 3.0.8

Humanizer.InflectorExtensions

InflectorExtensions Class​

public static class InflectorExtensions

Inheritance System.Object → InflectorExtensions

Methods​

InflectorExtensions.Camelize(this string) Method​

Converts a string to camelCase (lowerCamelCase) by capitalizing the first letter of each word except the first word, and removing spaces, underscores, and dashes.

public static string Camelize(this string input);

Parameters​

input System.String

The string to be camelized. Must not be null.

Returns​

System.String
A camelCase version of the input where the first word starts with a lowercase letter, subsequent words start with uppercase letters, and spaces, underscores, and dashes are removed.

Example​

"some_property_name".Camelize() => "somePropertyName"
"some property name".Camelize() => "somePropertyName"
"SomePropertyName".Camelize() => "somePropertyName"

Remarks​

camelCase is the same as PascalCase except the first character is lowercase. It's commonly used for variable and method parameter names in .NET.

InflectorExtensions.Dasherize(this string) Method​

Replaces all underscores in the string with dashes (hyphens).

public static string Dasherize(this string underscoredWord);

Parameters​

underscoredWord System.String

The string containing underscores to be replaced with dashes. Must not be null.

Returns​

System.String
A string with all underscores replaced by dashes.

Example​

"some_property_name".Dasherize() => "some-property-name"
"some_longer_property_name".Dasherize() => "some-longer-property-name"

Remarks​

This is typically used after calling Underscore(this string) to convert from underscore_case to dash-case (kebab-case).

InflectorExtensions.Hyphenate(this string) Method​

Replaces all underscores in the string with hyphens. This is an alias for Dasherize(this string).

public static string Hyphenate(this string underscoredWord);

Parameters​

underscoredWord System.String

The string containing underscores to be replaced with hyphens. Must not be null.

Returns​

System.String
A string with all underscores replaced by hyphens.

Example​

"some_property_name".Hyphenate() => "some-property-name"

Remarks​

This method is functionally identical to Dasherize(this string) and is provided for API clarity.

InflectorExtensions.Kebaberize(this string) Method​

Converts a string to kebab-case (lowercase words separated by hyphens), transforming PascalCase, camelCase, spaces, and underscores into hyphenated lowercase text.

public static string Kebaberize(this string input);

Parameters​

input System.String

The string to be converted to kebab-case. Must not be null.

Returns​

System.String
A lowercase string with words separated by hyphens.

Example​

"SomePropertyName".Kebaberize() => "some-property-name"
"somePropertyName".Kebaberize() => "some-property-name"
"some property name".Kebaberize() => "some-property-name"
"some_property_name".Kebaberize() => "some-property-name"

Remarks​

Kebab-case is commonly used for CSS class names, HTML attributes, and URL slugs. This is equivalent to calling Underscore(this string) followed by Dasherize(this string).

InflectorExtensions.Pascalize(this string) Method​

Converts a string to PascalCase (UpperCamelCase) by capitalizing the first letter of each word and removing spaces, underscores, and dashes.

public static string Pascalize(this string input);

Parameters​

input System.String

The string to be pascalized. Must not be null.

Returns​

System.String
A PascalCase version of the input where each word starts with an uppercase letter and spaces, underscores, and dashes are removed.

Example​

"some_property_name".Pascalize() => "SomePropertyName"
"some property name".Pascalize() => "SomePropertyName"
"some-property-name".Pascalize() => "SomePropertyName"

Remarks​

PascalCase (also known as UpperCamelCase) is commonly used for class names and type names in .NET.

InflectorExtensions.Pluralize(this string, bool) Method​

Converts a singular word to its plural form, handling both regular and irregular pluralizations.

public static string? Pluralize(this string? word, bool inputIsKnownToBeSingular=true);

Parameters​

word System.String

The word to be pluralized. Can be null.

inputIsKnownToBeSingular System.Boolean

Indicates whether the input is known to be in singular form. Set to true (default) if you're certain the word is singular. Set to false if the word might already be plural, in which case the method will check and avoid double-pluralization.

Returns​

System.String
The plural form of the word, or null if the input was null. Handles irregular plurals (e.g., "person" → "people", "child" → "children") and regular plurals (e.g., "cat" → "cats").

Example​

"person".Pluralize() => "people"
"cat".Pluralize() => "cats"
"box".Pluralize() => "boxes"
"man".Pluralize() => "men"
"cats".Pluralize(inputIsKnownToBeSingular: false) => "cats" (avoids double pluralization)

Remarks​

Uses the default vocabulary which includes English pluralization rules and common irregular forms.

InflectorExtensions.Singularize(this string, bool, bool) Method​

Converts a plural word to its singular form, handling both regular and irregular singularizations.

public static string Singularize(this string word, bool inputIsKnownToBePlural=true, bool skipSimpleWords=false);

Parameters​

word System.String

The word to be singularized. Must not be null.

inputIsKnownToBePlural System.Boolean

Indicates whether the input is known to be in plural form. Set to true (default) if you're certain the word is plural. Set to false if the word might already be singular, in which case the method will check and avoid incorrect singularization.

skipSimpleWords System.Boolean

When true, skips singularization of simple words that just end in 's'. This helps avoid incorrectly singularizing words like "ross" to "ros".

Returns​

System.String
The singular form of the word. Handles irregular singulars (e.g., "people" → "person", "children" → "child") and regular singulars (e.g., "cats" → "cat").

Example​

"people".Singularize() => "person"
"cats".Singularize() => "cat"
"boxes".Singularize() => "box"
"men".Singularize() => "man"
"person".Singularize(inputIsKnownToBePlural: false) => "person" (avoids incorrect singularization)

Remarks​

Uses the default vocabulary which includes English singularization rules and common irregular forms.

InflectorExtensions.Titleize(this string) Method​

Converts a string to title case by humanizing it first and then applying title casing. Each word in the result will start with an uppercase letter.

public static string Titleize(this string input);

Parameters​

input System.String

The string to be converted to title case. Must not be null.

Returns​

System.String
A humanized string with each word capitalized (title case). If humanization produces an empty string, returns the original input unchanged.

Example​

"some_title".Titleize() => "Some Title"
"someTitle".Titleize() => "Some Title"
"some-package_name".Titleize() => "Some Package Name"

Remarks​

This method first humanizes the input (breaking up PascalCase, underscores, etc.) and then applies title casing.

InflectorExtensions.Underscore(this string) Method​

Converts a string to lowercase and separates words with underscores, transforming PascalCase, camelCase, and spaces into underscore_case.

public static string Underscore(this string input);

Parameters​

input System.String

The string to be underscored. Must not be null.

Returns​

System.String
A lowercase string with words separated by underscores instead of spaces, case changes, or dashes.

Example​

"SomePropertyName".Underscore() => "some_property_name"
"somePropertyName".Underscore() => "some_property_name"
"some-property-name".Underscore() => "some_property_name"
"some property name".Underscore() => "some_property_name"

Remarks​

This transformation is commonly used for database column names, file names, and URL slugs in some conventions.