The first time I study expression trees. I have a few basic doubts.
Essentially, an expression accepts only a lambda expression. Ans, then we can compile () the lambda expression for the MSIL code, which in turn returns a common delegate. We can call the returned delegate as is. Do I understand correctly?
If this is exactly what I'm trying to achieve: ((10*5)+(9/4))
BinaryExpression b1 = Expression.MakeBinary(ExpressionType.Multiply, Expression.Constant(10), Expression.Constant(5));
BinaryExpression b2 = Expression.MakeBinary(ExpressionType.Divide, Expression.Constant(9), Expression.Constant(4));
BinaryExpression b4 = Expression.MakeBinary(ExpressionType.Add, b1, b2);
So at that moment we did lambda expression body. Now, to turn it into full lambda expression, we need to call
Console.WriteLine(Expression.Lambda<Func<int, int>>(b4).Compile());
I do not get this part. And that also does not work.
Why is this Func<int,int>?
It seems that the internal expressions will only accept int as param, and the whole expression will return int?
Obviously this does not work. What does the generated lambda look like?
Am I getting the whole picture? How to do it?