Chapter 6. Generating code with expressions
This chapter covers
- Using code as data
- Using the power of expression trees
- Improving code with expressions
As you saw in chapter 5, you can use the Reflection.Emit APIs to create dynamic code that you can execute at runtime. This requires intimate knowledge of IL. Let’s be honest: learning IL isn’t a skill set that most .NET developers have, nor is it one they necessarily want to acquire, even if they’re interested in metaprogramming techniques. The reason is simple: writing code in IL can easily lead to incorrect implementations and requires a mental model of code execution in .NET that’s not as intuitive as the one a high-level language provides.
Fortunately, there’s another API in .NET that ...
Get Metaprogramming in .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.