我正在为nHibernate动态构建linq查询。
由于依赖关系,我希望稍后可以强制转换/检索类型化表达式,但到目前为止我一直没有成功。
以下代码不起作用(强制转换应该在其他地方发生):
var funcType = typeof (Func<,>).MakeGenericType(entityType, typeof (bool));
var typedExpression = (Func<T, bool>)Expression.Lambda(funcType, itemPredicate, parameter); //Fails
这是有效的:
var typedExpression = Expression.Lambda<Func<T, bool>>(itemPredicate, parameter);
是否可以从LambdaExpression中获取“封装”类型的表达式?