The first pre-release of new ASP.Net MVC (ahem, Ruby-on-Rails for .Net) framework has just been made public.

I find it really exciting that Scott Guthrie and his team are listening to what the people want. Webforms is really quite heavy, especially in comparison to Ruby on Rails, so by offering new frameworks Microsoft will gain new developers. And new developers equals more servers, so it’s a good business model, methinks.

A major plus for me is seeing how the Framework shows off the new C# 3.0 features. I love Python and Ruby, but with no support yet for Visual Studio, it’s not easy to use them. Until now, the expressiveness of Python and Ruby have been missing from C# - it grew up from Java after all – but C# 3.0 is now moving towards that expressiveness too. With XAML and C#, things have really changed for developers over the past 5 or so years.

For example, check out this post from Rob Conery. He demonstrates an extension method which allows you to create a list of attributes as a string. You just call “ToAttributeList()” on any object, and you get a string back like “field1=”0″ field2=”1″”.

I can already think of loads of places where I would like to use that. There’s already a “ToDictionary()” method in the .Net 3.5 Framework, which can be used to create a dictionary from a list of objects, using a field as the key, but I can create a dictionary directly using the property names as keys, with the objects as values.

public static Dictionary<string, object> ToPropertyHash(this object item)
{
  var props = from property in item.GetType().GetProperties()
              select new {Name=property.Name, Value=property.GetValue(item, null)};

var dict = new Dictionary<string, object>();
foreach(var prop in props)
{
dict.Add(prop.Name, prop.Value);
}

return dict;
}

Here’s testing code which demonstrates what you get.

var myObject = new { Name = “Frank”, Age = 5 };
var dict = myObject.ToPropertyHash();
CollectionAssert.Contains(dict.Keys, “Name”);
CollectionAssert.Contains(dict.Keys, “Age”);
Assert.AreEqual(dict[“Name”], “Frank”);
Assert.AreEqual(dict[“Age”], 5);

Maybe that’s not so interesting for you, but I am developing Windows Workflow Foundation apps, and a workflow instance always requires you to build a new dictionary with the names of the properties as keys. This could be very, very helpful to cut down on code for that.

Instead of …

Dictionary<string, object> args = new Dictionary<string, object>();
args.Add(“Name”, “Richard Bushnell”);
args.Add(“Age”, 32);
args.Add(“NoOfKids”, 5);

… I use:

var args = new { Name = “Richard Bushnell”, Age = 32, NoOfKids = 5 }.ToPropertyHash();

What I cannot understand yet, is why Microsoft has to copy Ruby On Rails? Don’t get me wrong, I love Rails. But in some places it just doesn’t suit ASP.net development. ASP.net developers already have their ways of working, and have bought controls, etc. Why force them to not use them anymore, if they just want to tidy up their code with a new MVC model? Wouldn’t it be best for everyone if they developed another kind of framework? The focus could be on testing, as with MVC, but more directed towards developers who already use WinForms and WebForms.

Microsoft can develop independently. Take LINQ, for example. The .Net team could have simply provided list comprehensions as implemented in Python, but instead, they came up with a totally new model which no other development framework has ever had. And while XAML is similar to the old Delphi DFM files, it’s still taken some good leaps forward. I don’t see that yet with the ASP.Net MVC Framework. They’re still playing catch-up with Rails.

In general though, I’m really excited to watch it developing.