Reasoning about Expressions
So far, we’ve looked at the powerful metadata that is captured and how we can access it using reflection. We’ve also looked at how we can leverage this same metadata and generate code on the fly at runtime.
Using reflection and generating code as techniques in metaprogramming are extremely powerful, but they’re not applicable to all scenarios. It can also be very involved and produce hard-to-read and maybe even hard-to-maintain code going deep with reflection and proxy generation.
C# expressions can, for a lot of scenarios, represent a better approach or an additional approach for specific scenarios for doing runtime discovery and extraction of metadata.
We will cover the following topics in this chapter:
- What are expressions?
- Traversing an expression tree
- Using expressions as descriptors of members on types
From this chapter, you should understand what expressions are and how you can leverage them as...