我正在为nHibernate动态构建linq查询.
由于依赖关系,我想在以后转换/检索类型化的表达式,但到目前为止我还没有成功.
这不起作用(演员应该发生在其他地方):
var funcType = typeof (Func<,>).MakeGenericType(entityType, typeof (bool));
var typedExpression = (Func<T, bool>)Expression.Lambda(funcType, itemPredicate, parameter); //Fails
Run Code Online (Sandbox Code Playgroud)
这是有效的:
var typedExpression = Expression.Lambda<Func<T, bool>>(itemPredicate, parameter);
Run Code Online (Sandbox Code Playgroud)
是否有可能从LambdaExpression获取'封装'类型表达式?