Created
May 27, 2013 21:08
-
-
Save caseywatson/5659091 to your computer and use it in GitHub Desktop.
PluralizationService + Extension Methods = AWESOME
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Data.Entity.Design.PluralizationServices; | |
| using System.Globalization; | |
| using System.Text; | |
| namespace Modelio.Core | |
| { | |
| public static class StringExtensions | |
| { | |
| public static string Pluralize(this string source) | |
| { | |
| if (String.IsNullOrEmpty(source)) | |
| throw new ArgumentException("Source is required.", "source"); | |
| PluralizationService pluralService = PluralizationService.CreateService(CultureInfo.CurrentCulture); | |
| if (pluralService.IsPlural(source)) | |
| return source; | |
| return pluralService.Pluralize(source); | |
| } | |
| public static string Singularize(this string source) | |
| { | |
| if (String.IsNullOrEmpty(source)) | |
| throw new ArgumentException("Source is required.", "source"); | |
| PluralizationService pluralService = PluralizationService.CreateService(CultureInfo.CurrentCulture); | |
| if (pluralService.IsSingular(source)) | |
| return source; | |
| return pluralService.Singularize(source); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment