The blog of Eric Sibly; focusing on mountain biking, .NET development for the Desktop, Smartphone and PocketPC.

Monday, July 16, 2007

Partial Methods

Finally Partial Methods have been added that complement Partial Classes; which in turn makes Partial Classes much more interesting and a hell of a lot more flexible.

A major challenge with Partial Classes previously as I saw it was where code was generated there was then no flexible opt-in means to hook in additional user code that the generated code would initiate, other than providing virtual or protected methods and subclassing which all just adds another layer of redundancy (and comes with a performance hit).

A Partial Method provides similar functionality in that a method interface/template is created and optionally the corresponding implementation can be added within the same class. Where it is not added the compiler is smart enough to ignore – zero performance overhead – nice!

There are some limitations and rules - see the first link for a decent run through.