Func<int,bool> f = (p)=>{ return p>0 && p<9 || p==12};
这样的委托?
Expression.And 只能传入两个条件,我想一次传入两个以上的条件 。
------解决方案--------------------
var par = Expression.Parameter(typeof(int), "p");
var left = Expression.AndAlso(Expression.GreaterThan(par, Expression.Constant(0)), Expression.LessThan(par, Expression.Constant(9)));
var right = Expression.Equal(par, Expression.Constant(23));
var s = Expression.Lambda(Expression.OrElse(left, right), par);
Console.WriteLine((s.Compile() as Func<int,bool>)(2));