将表达式转换为Expression< Func< T,bool> [英] Convert Expression to Expression<Func<T, bool>>

查看:88
本文介绍了将表达式转换为Expression< Func< T,bool>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在 T 上创建了Expression的实例,是否可以将 Expression 转换为 Expression< Func< T,bool>> ?

Is that possible to convert Expression to Expression<Func<T, bool>> if instance of Expression was created on T ?

最后,我具有列表 List< Expression> ,并且需要在 Expression< Func< T,bool>> 上生成,其中 List<; Expression> AND 聚合.

At the end I have list List<Expression> and need to produce on Expression<Func<T, bool>> where each expression of List<Expression> is agregated with AND.

推荐答案

是;只需调用 Expression.Lambda< Func< T,bool>>(...,参数),其中 ... 是一个由您要表达的表达式组成的表达式结合起来.

Yes; just call Expression.Lambda<Func<T, bool>>(..., parameter), where ... is an expression composed of the expressions you want to combine.

您可能想要 list.Aggregate(Expressions.AndAlso).

如果您的表达式并不都共享相同的 ParameterExpression ,则需要对其进行重写.(使用 ExpressionVisitor )

If your expressions don't all share the same ParameterExpression, you'll need to rewrite them to do so. (use ExpressionVisitor)

这篇关于将表达式转换为Expression&lt; Func&lt; T,bool&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆