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 7. Generating code with IL rewriting

This chapter covers

  • The benefits of code rewriting
  • Using libraries to rewrite assemblies
  • Debugging injected code

Throughout part 2 (beginning in chapter 3) you’ve seen a number of techniques and frameworks that you can use to generate code at various stages of execution. But there’s one area of code execution that we’ve not yet addressed. It’s after compilation, when your code has been turned into IL that’s stored in an assembly. At that point, your code is in a format that the CLR uses to run your code, and most developers think the assembly is frozen at that point—that it can’t be changed. But that’s not the case!

In this chapter, you’ll see how to rewrite assemblies to inject common code ...

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