This one was inspired by my language-guru co-worker who can't seem to find a good use for them, and after a few lame attempts of my own, I'd have to agree.
Now I know these concepts tend to flow a lot more easily once you get some good practical reasons down.
At the moment it seems as though its only purpose is to allow you to write a Linq provider?
Is that it?? Is there any other benefits to this?
When you want to have a richer interaction, you need to use Expression Trees. Expression Trees represent code as a structure that you can examine, modify, or execute. These tools give you the power to manipulate code during run time. You can write code that examines running algorithms, or injects new capabilities.
NET, Expression is an abstract class which contains static methods and inherited by various types (like ParameterExpression, MethodCallExpression, BinaryExpression etc.) to create expression tree nodes of specific types. Also all these expression-specific expression tree types are defined in System. Linq.
Expression tree is an in-memory representation of a lambda expression. It holds the actual elements of the query, not the result of the query. The expression tree makes the structure of the lambda expression transparent and explicit.
Expression tree are so powerful because they let you treat code like data. Users are accustomed to building up data, saving it and coming back to it later.
Expression trees let you do the same thing with code. For example you can take your user's input (check-boxes, number ranges, etc.) and translate it into an Expression tree. That expression tree can then be executed, or stored off for later use. Very cool.
Think of the practical uses around reporting like building up and saving data filters and data mappings. Another practical use would be to support custom work flows in your application based on user defined rules.
Here's a bit of MSDN code on serializing expression trees (http://code.msdn.microsoft.com/exprserialization) that should get the ideas flowing.
You can use Expression Trees to transform a domain language into executable code.
A Solution looking for a problem eh?
Expression trees allow you to present code as a transformable data-structure, hence they are perfect for transforming between languages Linq To SQL being the most powerful currently.
An other use apart from DSLs (which is transformation) is parallelization (which is spliting) and example in that space is PLINQ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With