Last active
December 16, 2015 19:29
-
-
Save markryd/5485495 to your computer and use it in GitHub Desktop.
Building expressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Original | |
| var param = Expression.Parameter(typeof(string), "p"); | |
| var len = Expression.PropertyOrField(param, "Length"); | |
| var body = Expression.Equal( | |
| len, Expression.Constant(5)); | |
| var lambda = Expression.Lambda<Func<string, bool>>( | |
| body, param); | |
| //Updated | |
| //re (p.Length== 5) && (p.SomeOtherProperty == "hello"): | |
| var param = Expression.Parameter(typeof(SomeType), "p"); | |
| var body = Expression.AndAlso( | |
| Expression.Equal( | |
| Expression.PropertyOrField(param, "Length"), | |
| Expression.Constant(5) | |
| ), | |
| Expression.Equal( | |
| Expression.PropertyOrField(param, "SomeOtherProperty"), | |
| Expression.Constant("hello") | |
| )); | |
| var lambda = Expression.Lambda<Func<SomeType, bool>>(body, param); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment