O'Reilly logo

Metaprogramming in .NET by Kevin Hazzard and Jason Bock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required