Skip to main content
Version: 4.0 (next)

Humanizer.EnumHumanizeExtensions

EnumHumanizeExtensions Class

Contains extension methods for humanizing Enums

public static class EnumHumanizeExtensions

Inheritance System.Object → EnumHumanizeExtensions

Methods

EnumHumanizeExtensions.Humanize(this Enum) Method

Converts an enum value to a human-readable string when the concrete enum type is only known at runtime.

public static string Humanize(this System.Enum input);

Parameters

input System.Enum

The enum value to be humanized.

Returns

System.String
A human-readable string representation of the enum value.

EnumHumanizeExtensions.Humanize(this Enum, LetterCasing) Method

Converts an enum value to a human-readable string with the specified letter casing applied to the enum member name when the concrete enum type is only known at runtime. Authored metadata on a defined enum value is returned unchanged.

public static string Humanize(this System.Enum input, Humanizer.LetterCasing casing);

Parameters

input System.Enum

The enum value to be humanized.

casing LetterCasing

The desired letter casing to apply when humanizing the enum member name.

Returns

System.String
A human-readable string representation of the enum value.

EnumHumanizeExtensions.Humanize(this Enum, LetterCasing, EnumHumanizeSource) Method

Converts an enum value to a human-readable string using the specified casing and source when the concrete enum type is only known at runtime.

public static string Humanize(this System.Enum input, Humanizer.LetterCasing casing, Humanizer.EnumHumanizeSource source);

Parameters

input System.Enum

The enum value to be humanized.

casing LetterCasing

The desired letter casing to apply when humanizing the enum member name.

source EnumHumanizeSource

The source used to humanize the enum value.

Returns

System.String
A human-readable string representation of the enum value.

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 to the enum member name. Authored metadata on a defined enum value is returned unchanged.

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 when humanizing the enum member name.

Returns

System.String
A human-readable string representation of the enum value. If a defined enum value has authored metadata such as System.ComponentModel.DescriptionAttribute, its value is returned unchanged.

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

For a defined enum value, the specified casing is applied only when the output is derived from the enum member name.

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

Converts an enum value to a human-readable string using the specified casing and source.

public static string Humanize<T>(this T input, Humanizer.LetterCasing casing, Humanizer.EnumHumanizeSource source)
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 when humanizing the enum member name.

source EnumHumanizeSource

The source used to humanize the enum value.

Returns

System.String
A human-readable string representation of the enum value.