【发布时间】:2011-11-07 10:39:46
【问题描述】:
我想创建一个接受Expression<Func<T, bool>> 并创建它的逻辑逆的方法(即它会返回false,而它会返回true,反之亦然。这比我更难心想。这就是我要做的:
public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> expression)
{
return Expression.Lambda<Func<T, bool>>(Expression.Not(expression.Body));
}
编译正常,但调用时抛出以下异常:
Test method Tests.Common.Unit.LinqPredicateBuilderTests.CanInverseAPredicate threw exception:
System.ArgumentException: Incorrect number of parameters supplied for lambda declaration
我不知道我在做什么。有谁可以填空吗?
【问题讨论】:
-
inverse 有点误导。我理解为从输出计算输入。
-
我很抱歉。我的术语跟不上。
标签: c# linq expression-trees