How to combine (OR) two expression trees

c# expression-trees

Question

I have two expression trees of type : Expression<Func<string, bool>> and I would like to obtain a single Expression that will do the OR of the two expressions (passing the same string parameter to both expressions) Any idea?

Popular Answer

You can use PredicateBuilder from LINQKit to do this. For example:

Expression<Func<string, bool>> e1 = …;
Expression<Func<string, bool>> e2 = …;
Expression<Func<string, bool>> combined = e1.Or(e2).Expand();


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow