Enum and collection scenarios
Enums and collections both become readable presentation text, but their contracts are different. Enum conversion maps between a typed member and a label, while collection humanization delegates conjunction and punctuation to a locale-aware formatter.
- Enums and flags covers metadata, case-insensitive parsing, no-match behavior, flags, and AOT-safe overload choice.
- Collections and tuple names covers list punctuation, display selectors, custom formatters, and multiplicity words.
Example
This program shows a description override, case-insensitive enum dehumanization, and an English collection:
using System.ComponentModel;
using System.Globalization;
using Humanizer;
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
string[] drinks = ["tea", "coffee", "water"];
var people = new[] { new Person("Ada"), new Person("Grace") };
Console.WriteLine($"State: {OrderState.AwaitingPayment.Humanize()}");
Console.WriteLine($"Parsed: {"WAITING FOR PAYMENT".DehumanizeTo<OrderState>()}");
Console.WriteLine($"Drinks: {drinks.Humanize()}");
Console.WriteLine($"People: {people.Humanize(person => person.DisplayName)}");
enum OrderState
{
[Description("Waiting for payment")]
AwaitingPayment,
ReadyToShip
}
record Person(string DisplayName);
State: Waiting for payment
Parsed: AwaitingPayment
Drinks: tea, coffee, and water
People: Ada and Grace
The source also projects Person records to display names. Follow the focused pages for flags, unknown values, localized punctuation, and custom formatters.
Make labels unambiguous and culture explicit
Enum labels must be unambiguous even though matching is case-insensitive. The default no-match behavior throws. Collection output is culture-specific; scope CurrentUICulture before formatting in tests or background work.
For trimmed or Native AOT code, prefer generic enum APIs. The runtime Type dehumanization overload uses reflection and carries linker/AOT warnings.