Partial methods

Fri, August 3, 2007, 02:41 AM under Orcas | VisualStudio
With VS2008 Beta 2, we all get a chance to play with a feature that the product teams have been teasing us with by talking about it before it was available in public drops.

[Request to product teams]If your feature is not baked in public bits, please refrain from blogging about it; also please stop posting images of private bits.[end request]

The feature in question is Partial Methods. Wes has an excellent write up here from a C# perspective (that he followed with this) and Scott here from a VB perspective. I suggest you read both since at the conceptual level they are the same. Essentially it is an aid to code generation scenarios in the same way that partial classes are. Think of it as a combination of a more efficient version of private event handlers and the Conditional attribute. Read the previous links for the full story.

My take? I simply thought I'd see the feature in action so without referring to the posts or documentation I fired up Visual Studio to try it out from memory. How mistaken I was. Every time I tried something I was greeted with a compiler error pointing out my ignorance. I was going to post here the series of compiler errors I dealt with one by one until I managed to get the thing to compile, but instead I've tried to summarise a few of them with one line of code:

public partial bool GoGoGo(out int i); //produces the following Error List


What better way to learn than by the compiler teaching you... a bit like how kids learn that fire is hot... by touching it (well, that's the way I learnt anyway). If however you prefer reading a very long thorough post covering a feature (in addition to the 3 posts above by the product teams) and also prefer looking at things through ildasm, then head over to Bart's blog post on the topic.
Comments are closed.