【发布时间】:2012-12-17 09:51:36
【问题描述】:
我正在编写表达式扩展方法,该方法必须反转 bool 类型的 lambda 表达式。
这是我正在做的事情:
public static Expression<Func<T, bool>> Inverse<T>(this Expression<Func<T, bool>> e)
{
return Expression.Lambda<Func<T, bool>>(Expression.Not(e));
}
但这引发了一个例外,即unary operator is NOT not defined for the type Func<int,bool>。
我也试过这个:
public static Expression<Func<T, bool>> Inverse<T>(this Expression<Func<T, bool>> e)
{
return Expression.Lambda<Func<T, bool>>(Expression.Not(e.Body));
}
但是得到这个:Incorrent number of parameters supplied for lambda declaration。
【问题讨论】:
标签: c# lambda expression