I’m just in the early process of learning about expression trees.
As far as I understand, the good thing about them is that they can be parsed when they are used as parameters, so for instance:
Foo.Bar(x => x.Process == "On" && x.Name == "Goofy")
But how can I parse the expression when there is AND inside?
Maybe I’ve misunderstood it all, but then I can’t see the reason for using expressions? I’ve now looked at nearly hundreds of websites that all try to explain what an expression tree are and they all succeeded, expect they never explained what the use was – except the trivial explanation “An expression tree is not compiled….”
I have used Expressions to build a trivial Domain Specific Language. This is used in an actual application where I work, so it’s not a toy project.
I basically created a fluent interface that allows me to build
Predicate<T>delegates, something like:Each method adds the relevant expression to the current tree. Than
ToPredicatecompiles the expression to the delegate.The
GreaterThanConstmethod looks something like:Where
conditionis the member that holds the tree that’s being built (grown?).To parse your expression, you’d need to write something like:
Then you can look though the expression tree that is generated and see what’s there.