小编Lar*_*ntz的帖子

如何将LambdaExpression转换为类型化表达式<Func <T,T >>

我正在为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获取'封装'类型表达式?

.net c# lambda casting linq-expressions

17
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

casting ×1

lambda ×1

linq-expressions ×1