Blog

Ruby-like Hash in C# (sharp)

One of the things I like about ruby is that you get more done with less typing, and though c# is a powerful language, Ive been wishing for a ruby like hash and even array initializers. Ive been spending some time doing an ruby on rails active record port to c#, and lately ive been porting over the rails migration ( I even have a prototype working with SQL 2005). However, one thing heavily missing from the c# recipe is the Ruby like Hash for doing migrations. So after some research on the web, I found Alex Henderdon & Andrey Shchekins ruby like hash function for c#. However this didnt exactly take this concept all the way as it could have, so after some tweaks to a Dictionary>string, object

p>

     Hash h = Hash.New(Name => "Michael Herndon", Age => 10, Url => "www.myspace.com");     h["Name"].ShouldBe("Michael Herndon");     h["Age"].ShouldBe(10);     h["Url"].ShouldBe("www.myspace.com");

Ive also packed up Andrew Peters Inflector.Net using C#s mixins. Infector.Net is based off of the class rail uses to do things like camelize, pluralize etc. Also Ive put together some other rails like mixins like .Gsup, .Merge, .Each. Collect, .Join, for people to enjoy. If you want to take a peak at code, its on the amplify-net googlecode project inside the folder Framework/Amplify.Linq folder.

     svn checkout https://amplify-net.googlecode.com/svn/trunk/ amplify-net     url: http://code.google.com/p/amplify-net