Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiple Expression.Or

How to build an expression which will produce the following statement?

x => x.Parameter1 == "Some text" || x.Parameter2 == "Some text" || x.Parameter3 == "Some text"

It’s not hard to do x =>, but how to create those many OR operators?

I know we have Expression.Or method, but it only accepts 2 arguments.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks.

>Solution :

So you just compile them together

psuedo code:

firstOr = Expression.Or(x.Parameter2 == "some test", x.Parameter3 == "sometest")

secondOr = Expression.Or(firstOr, x.Parameter1 == "Some text");

Then all you do is evaluate the secondOr

These are expression trees , and therefor you compose them together.

when you have multiple elements, segment as you would with a mathematical expression, put parenthesis around parts:

1 + 2 + 5 = 8

this is

(1 + 2) + 5 = 8

So we’ve turned 1 expression into a composition of 2 expressions.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading