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

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.