-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expression Compiler
Akash Kava edited this page Oct 13, 2021
·
3 revisions
All expressions are prefixed with Y
, and can be constructed easily as shown below.
var a = YExpression.Parameter(typeof(int));
var b = YExpression.Parameter(typeof(int));
var exp = YExpression.Lambda<Func<int,int,int>>("add",
YExpression.Binary(a, YOperator.Add, b),
new YParameterExpression[] { a, b });
var fx = exp.Compile();
Assert.AreEqual(1, fx(1, 0));
Assert.AreEqual(3, fx(1, 2));
This method will compile expression to IL in memory, it will not analyze nested lambdas, this is by design to generate IL faster. For nested lambda, please use CompileWithNestedLambdas
method. It will return DynamicMethod delegate.
When you expression tree contains nested lambda with closures, use this method to generate the IL. It will return DynamicMethod delegate.
This is similar to CompileToMethod
, this method generate an empty assembly and it will return generated method from MethodBuilder
.
This is same as CompileToMethod
of Linq.
You can compile lambda with this
parameter to an instance method.