String - ToPlural
A string extension method that converts the string object to a plural.
public static string FileName = "test.txt"; public static void Main() { string [] input = {"Entity", "Student", "Course", "Class", "Language"}; foreach(var str in input) { //C# Extension Method: String - ToPlural var output = str.ToPlural(); Console.WriteLine(output); } }
View Source
#if !NETSTANDARD using System.Data.Entity.Design.PluralizationServices; using System.Globalization; #endif public static partial class Extensions { #if !NETSTANDARD /// <summary> /// A string extension method that converts the @this to a plural. /// </summary> /// <param name="this">The @this to act on.</param> /// <returns>@this as a string.</returns> public static string ToPlural(this string @this) { return PluralizationService.CreateService(new CultureInfo("en-US")).Pluralize(@this); } /// <summary> /// A string extension method that converts the @this to a plural. /// </summary> /// <param name="this">The @this to act on.</param> /// <param name="cultureInfo">Information describing the culture.</param> /// <returns>@this as a string.</returns> public static string ToPlural(this string @this, CultureInfo cultureInfo) { return PluralizationService.CreateService(cultureInfo).Pluralize(@this); } #endif }