开发者

Using LinqBridge in .Net2.0 Website

has anyone been able to use Linqbridge on a .Net 2.0 Website? I have no problem using it in a normal .Net 2.0 console, but when I use 开发者_JAVA百科the methods in the website, I get

Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification


I think the error message is pretty clear. Extension methods aren't supported in 2.0. If you want to use an extension method in 2.0, you'd need to modify it by removing the this and call it explicitly.

If you had:

public static class ExtensionMethods {
    public static bool IsOdd(this int x) {
        return x % 2 != 0;
    }
}

Then ExtensionMethods and code like number.IsOdd() won't compile.

You'd need to remove the this in the IsOdd method signature and call it as ExtensionMethods.IsOdd(number) to get it to work under 2.0.

If I recall correctly, that's the approach the authors of LinqBridge used.

Hope that helps.


Maybe you're confusing .NET and C# versions. LINQBridge supports .NET 2.0, but you still need C# 3.0 or later (i.e. VS2008 or later) to compile code with extension method or LINQ syntax sugar. Once compiled, the assembly runs without issue on .NET 2.0 runtimes. That's the benefit of LINQBridge.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜