When generating code for Entity Framework with T4, you sometimes need to singularize or pluralize a name (e.g., GetCustomer, GetAllCustomers). This can be tricky to implement due to the many irregular forms (e.g., man/men, child/children). Fortunately, Microsoft provides a built-in utility for this, at least for English: PluralizationService.
Usage is straightforward:
C#
PluralizationService pluralizationService = PluralizationService.CreateService(new CultureInfo("en"));
Console.WriteLine(pluralizationService.Pluralize("man"));
Other free libraries offer similar functionality. For example, CodeFluent Runtime supports both French and English via the GrammaticalNumberConverter class.
Do you have a question or a suggestion about this post? Contact me!