Building and Executing Expressions
Expressions in C# are not just great to use as a means of capturing metadata and reason about code; you can also generate expression trees, either based on code represented as lambdas, as we saw in Chapter 7, Reasoning about Expressions, or by programmatically adding the different expression node types yourself.
The expressions that you build can then be executed. And with the breadth of capabilities offered with expressions, they’re almost as powerful as generating intermediate language code, as we saw in Chapter 6, Dynamic Proxy Generation. Since every expression is code that sits inside the specific expression that is executed and performs the task of the expression, you can’t expect the same level of performance as with generating intermediate language that runs natively on the .NET runtime. So, it depends on your use case whether or not you should pick expression generation over proxy generation.
In this chapter, we will look...