Lambdas does not rely on any of the new features of the framework. A lambda, after all, should only be able to create a new class with fields, methods, and constructors, all of which are available in the 1.0 runtime.
The following code:
int value = 42; MyDelegate f = () => value;
Will be converted to a new named type:
public class SomeRandomCompilerGeneratedNameGoesHere { public int value; public int SomeGeneratedMethodName() {
And it will be used like this:
var closureClass = new SomeRandomCompilerGeneratedNameGoesHere(); closureClass.value = 42; MyDelegate f = closureClass.SomeGeneratedMethodName;
Now there are several situations that do not require all this; if there are no private values, some of these steps can be raised and optimizations added (i.e. the method can be made static to avoid creating an instance of the object), but the conversion given here can display any valid C # lambda, and, as you can see the code that he converted will be valid even in C # 1.0.
Servy
source share