I want to implement
Expression<Func<int, int, int>> Max = (p1,p2) => p1 > p2 ? p1:p2;
as an expression tree and tried
ParameterExpression LeftEx = Expression.Parameter(typeof(int), "p1");
ParameterExpression RightEx = Expression.Parameter(typeof(int), "p2");
BinaryExpression GroesserAls = Expression.GreaterThan(LeftEx, RightEx);
ConditionalExpression Cond = BinaryExpression.Condition(GroesserAls, LeftEx, RightEx);
Expression main = Cond.Test;
Expression<Func<int, int, bool>> Lam = Expression.Lambda<Func<int, int, bool>>(main,
new ParameterExpression[] { LeftEx, RightEx });
Console.WriteLine(Lam.Compile().Invoke(333, 1200));
With Cond, I either get true / false, but not LeftEx or RightEx, that the condition should return.
I did not find anything in the documentation.
Peter
source
share