Using LinqBridge in .Net2.0 Website

1.3k Views Asked by At

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 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
2

There are 2 best solutions below

1
On

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.

6
On

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.