我想实施
Expression<Func<int, int, int>> Max = (p1,p2) => p1 > p2 ? p1:p2;
Run Code Online (Sandbox Code Playgroud)
作为表达树并尝试过
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));
Run Code Online (Sandbox Code Playgroud)
使用Cond我要么得到真/假,而不是条件应该返回的LeftEx或RightEx.
我在文档中找不到任何内容.
彼得