Skip to main content
Version: 3.0.1

Humanizer.EnumHumanizeExtensions

EnumHumanizeExtensions Class

Contains extension methods for humanizing Enums

public static class EnumHumanizeExtensions

Inheritance System.Object → EnumHumanizeExtensions

Methods

EnumHumanizeExtensions.Humanize<T>(this T) Method

Converts an enum value to a human-readable string by intelligently formatting the enum member name and respecting any System.ComponentModel.DescriptionAttribute applied to the member.

public static string Humanize<T>(this T input)
where T : struct, System.Enum;

Type parameters

T

The enum type. Must be a struct and implement System.Enum.

Parameters

input T

The enum value to be humanized.

Returns

System.String
A human-readable string representation of the enum value. If the enum has the System.FlagsAttribute and multiple flags are set, returns a humanized, comma-separated list of the flag values. If a System.ComponentModel.DescriptionAttribute is present on the enum member, its value is returned. Otherwise, the enum member name is humanized (e.g., "AnonymousUser" becomes "Anonymous user").

Example

enum UserType { AnonymousUser, RegisteredUser }
UserType.AnonymousUser.Humanize() => "Anonymous user"

[Flags]
enum Permission { None = 0, Read = 1, Write = 2, Delete = 4 }
(Permission.Read | Permission.Write).Humanize() => "Read, Write"

enum Status
{
[Description("Currently active")]
Active
}
Status.Active.Humanize() => "Currently active"

Remarks

For flags enums, only non-zero flags are included in the output, and each flag is humanized individually. The humanization process converts PascalCase to space-separated text with appropriate capitalization.

EnumHumanizeExtensions.Humanize<T>(this T, LetterCasing) Method

Converts an enum value to a human-readable string with the specified letter casing applied. Respects any System.ComponentModel.DescriptionAttribute applied to the enum member.

public static string Humanize<T>(this T input, Humanizer.LetterCasing casing)
where T : struct, System.Enum;

Type parameters

T

The enum type. Must be a struct and implement System.Enum.

Parameters

input T

The enum value to be humanized.

casing LetterCasing

The desired letter casing to apply to the humanized enum value.

Returns

System.String
A human-readable string representation of the enum value with the specified casing applied. If a System.ComponentModel.DescriptionAttribute is present, its value is used and then cased.

Example

enum UserType { AnonymousUser, RegisteredUser }
UserType.AnonymousUser.Humanize(LetterCasing.AllCaps) => "ANONYMOUS USER"
UserType.AnonymousUser.Humanize(LetterCasing.Title) => "Anonymous User"
UserType.AnonymousUser.Humanize(LetterCasing.LowerCase) => "anonymous user"

Remarks

This is a convenience method that combines Humanize<T>(this T) with ApplyCase(this string, LetterCasing).