Wednesday, 20 August 2008

I love extension methods

Sometimes a feature can just help you out so much.

I have an existing .NET Framework 2.0 assembly which I don’t want to convert to a .NET Framework 3.5 assembly.  It would have ramifications on other projects / deployments.

However I have a .NET Framework 3.5 assembly which uses the .NET Framework 2.0 assembly where i need to use XElement off that class (ok I don’t need to but I want too).

I don’t particularly want to create a new class which inherits the old class, gets messy.  However by just simply creating an extension method for the original class from my .NET Framework 3.5 assembly, the whole issue goes away.

I can use my XElement based method in my .NET Framework 3.5 assembly and continue to use the existing object.  :)

One day when the original assembly is moved to .NET Framework 3.5 we can move this method to its rightful home but for just now job done :)



No comments: