ExtensionAttribute Visual Studio Item Template
Extension Methods are a new feature of Visual Studio 2008. They basically allow you to add new methods to already existing classes. You could for example introduce a new method: String.IsValidEmailAddress() which would validate whether the given string is a valid e-mail address. Scott Guthrie has written some more information about the Extension Methods in Visual Studio 2008.
There are two downsides of using Extension Methods though. First of all, they work in Visual Studio 2008 only. If you want to share some of your code with other developers using Visual Studio 2005 it won’t work and you can’t do anything about it. The other one is, that Extension Methods are available with the .NET 3x framework. There is actually a trick to use them in .NET 2.0 as well. Daniel Moth has presented a solution how it should be done. Although it’s not that much code and you could copy & paste it or copy the whole class between the project, I have decided to wrap it all up in a Visual Studio Item Template. The idea came up while I was working on a SharePoint Solution Visual Studio Project Template which will basically create a Visual Studio Solution according to our SharePoint development methodology (I will write more about it as soon as the template is more than meware).
By having the ExtensionAttribute available as an Item Template you can simply click with the right button on the particular project, choose Add > New Item:
Then you will choose Extension Attribute:
And the ExtensionAttribute class will get automatically added to your project without typing even one line of code:
You can download the Extension Attribute Visual Studio Item Template from our CodePlex site. I have wrapped it up in a Visual Studio Installer (.vsi) so it will automatically get installed in the right place.