Saturday, October 27, 2007

Learning new stuff

I have restarted a project that has languished for a number of years. I will save the description of the project for another post but the reason for doing this is to learn about all the new goodness in Orcas. So keep an eye out for more posts in this series.

Today I started to use a couple of new features. The first is the IEnumerable<> interface. We had the IEnumerable interface before but it has really grown up. What we have gained is a whole set of iteration based primitives. These include some simple ones like Contains. We could do this before on IList but now we have it on anything that is enumerable. The next primitive that I tried was the Aggregate function. This allows you to specify a function that will be used to combine each value in the enumeration.

I wanted to invoke a method (which returned a bool) on each element of the enumeration then combine these to see if the method returned true for all elements. I could do all this with one line of code:

m_parts.Aggregate(true, (prev, pred) => prev & pred.Apply(thing))

The true in there is the initial value for the aggregation. The second parameter is the new form for Lambda expressions/ anonymous methods. The way to read this is that the function takes two parameters the previous aggregate value and the next element. It combines the previous value with the value returned from calling the Apply method. It is pretty clever that the compiler can figure out all the types so this can be strongly typed without me having to specify them. The => notation is a very powerful thing but right now it doesn't feel very C# ish. I guess I need a little time to adjust.

The other new piece is actually more part of team suite - the testing support. I started just writing my tests using NUnit and running them through NUnit GUI (not as nice as resharper by far but functional). Then I found the add unit test menu item and I was taken down a different path. It is a pain that the attributes are all different but otherwise so far it seems quite workable. It handles the rebuilding and gives me the results in Visual Studio. There is plenty to try out yet so I will write more when I have used this more fully.

0 Comments:

Post a Comment

<< Home