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 preserving leading underscores, capitalizing the first letter of each word except the first word, and removing other spaces, underscores, dashes, and dots.
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 leading underscores are preserved, the first word starts
with a lowercase letter, subsequent words start with uppercase letters, and other separators are removed.
Example
"some_property_name".Camelize() => "somePropertyName"
"some property name".Camelize() => "somePropertyName"
"some.property.name".Camelize() => "somePropertyName"
"SomePropertyName".Camelize() => "somePropertyName"
"_some_property_name".Camelize() => "_somePropertyName"
Remarks
camelCase is the same as PascalCase except any leading underscores are preserved and the first character after them is lowercase. It's commonly used for variable and method parameter names in .NET. Casing is culture-invariant.
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). Casing is culture-invariant.
InflectorExtensions.Pascalize(this string) Method
Converts a string to PascalCase (UpperCamelCase) by capitalizing the first letter of each word and removing spaces, underscores, dashes, and dots.
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, dashes, and dots are removed.
Example
"some_property_name".Pascalize() => "SomePropertyName"
"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. Casing is culture-invariant.
InflectorExtensions.Pascalize(this string, bool) Method
Converts a string to PascalCase (UpperCamelCase), optionally normalizing uppercase sequences as words.
public static string Pascalize(this string input, bool preserveUppercase);
Parameters
input System.String
The string to be pascalized. Must not be null.
preserveUppercase System.Boolean
true to preserve uppercase sequences; false to normalize them as words.
Returns
System.String
A PascalCase version of the input.
Example
"SMS parameter provider".Pascalize(preserveUppercase: true) => "SMSParameterProvider"
"HTTP IO module".Pascalize(preserveUppercase: false) => "HttpIoModule"
Remarks
Uppercase sequences are split using identifier word boundaries, and casing is culture-invariant.
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"
"meter per second".Pluralize() => "meters per second"
"PERSON".Pluralize() => "PEOPLE"
"cats".Pluralize(inputIsKnownToBeSingular: false) => "cats" (avoids double pluralization)
Remarks
Uses the default vocabulary which includes English pluralization rules and common irregular forms. In compound rates separated by the word "per", the numerator is pluralized and the denominator is preserved.
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"
"meters per second".Singularize() => "meter per second"
"PEOPLE".Singularize() => "PERSON"
"person".Singularize(inputIsKnownToBePlural: false) => "person" (avoids incorrect singularization)
Remarks
Uses the default vocabulary which includes English singularization rules and common irregular forms. In compound rates separated by the word "per", the numerator is singularized and the denominator is preserved.
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.ToCamelCase(this string) Method
Converts a string to camelCase while preserving leading underscores and normalizing uppercase sequences as words.
public static string ToCamelCase(this string input);
Parameters
input System.String
The string to be converted. Must not be null.
Returns
System.String
A camelCase version of the input with leading underscores preserved and uppercase sequences normalized.
Example
"IOModule".ToCamelCase() => "ioModule"
"__XMLHttpRequest".ToCamelCase() => "__xmlHttpRequest"
Remarks
Uppercase sequences are split using identifier word boundaries, and casing is culture-invariant.
InflectorExtensions.ToPossessive(this string, bool, bool) Method
Converts an English noun or noun phrase to its possessive form.
public static string? ToPossessive(this string? word, bool inputIsPlural=false, bool useApostropheOnlyForSingularWordsEndingInS=false);
Parameters
word System.String
The noun or noun phrase to convert.
inputIsPlural System.Boolean
Whether word is plural.
useApostropheOnlyForSingularWordsEndingInS System.Boolean
Whether singular words ending in s should use only an apostrophe instead of 's.
Returns
System.String
The possessive form of word.
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. Casing is culture-invariant.
InflectorExtensions.Underscore(this string, bool) Method
Separates words with underscores, optionally preserving the input casing.
public static string Underscore(this string input, bool preserveCase);
Parameters
input System.String
The string to be underscored. Must not be null.
preserveCase System.Boolean
true to preserve the input casing; false to convert the result to lowercase.
Returns
System.String
A string with words separated by underscores.
Example
"SomePropertyName".Underscore(preserveCase: true) => "Some_Property_Name"
"HTMLParser".Underscore(preserveCase: true) => "HTML_Parser"
Remarks
Acronyms are split using identifier word boundaries, and lowercasing is culture-invariant.