Saturday, November 22, 2008

Extension method support in Compact Framework 2.0 applications

I had a discussion recently with my fellow MVPs and you can use C# 3.0 language features in a CF 2.0 app with VS 2008 and even extension methods with a small hack.

Simply create an ExtensionAttribute class:
using System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute{}
}
Then you need to declare this attribute on each extension method in order to implement extension methods. This is because extension methods require the new ExtensionAttribute class introduced in System.Core.dll in .NET 3.5.

Daniel Moth has talked about this in depth here.

No comments: