Inflector for .NET

I was writing conventions for FluentNHibernate the other day and I ran into the need to pluralize a given string and immediately thought of the ruby on rails Inflector.  It turns out there is a .NET library out there also capable of doing word inflection, originally written (I believe) by Andrew Peters, though the link I had no longer works.  The entire Inflector class is only a little over 200 lines long and can be easily included into any project, and contains the Pluralize() method along with a few other helpful methods (like Singularize(), Camelize(), Capitalize(), etc).

The Inflector class is available in its entirety from my github repository  In addition to the Inflector.cs class I added tests for every single method available so you can gain an understanding of what each method does.  Also, if you are wondering about a specific test case feel free to fork my project and add your own test cases to ensure Inflector does what you expect.

Here is an example of some test cases for pluralize:

TestData.Add("quiz", "quizzes");
TestData.Add("perspective", "perspectives");
TestData.Add("ox", "oxen");
TestData.Add("buffalo", "buffaloes");
TestData.Add("tomato", "tomatoes");
TestData.Add("dwarf", "dwarves");
TestData.Add("elf", "elves");
TestData.Add("mouse", "mice");
TestData.Add("octopus", "octopi");
TestData.Add("vertex", "vertices");
TestData.Add("matrix", "matrices");
TestData.Add("rice", "rice");
TestData.Add("shoe", "shoes");

Pretty smart stuff.

No Comments