我会责怪疲倦,尽管这个真的让我发挥了最大的作用
var result = Expression.Lambda<Func<T, bool>>(expression, parameterType).Compile();
出现错误:无法将类型"System.Func"隐式转换为"bool">
正如您可能已经猜到的那样,我需要它来返回到布尔值而不是 Func
提前致谢
public class Class1<T>
{
public Class1()
{
var result = Expression.Lambda<Func<T, bool>>(null, new[] {new ParameterExpression()});
var method = result.Compile();
bool result = method(new T());
}
}
这对我来说编译得很好。