In this chapter, I’ll show you the Emitter classes in .NET and how you can use your newfound knowledge of CIL to use these types effectively. I’ll go over each type in detail, discussing how they work to build assemblies and types on the fly. I’ll also explain ways to debug these dynamic assemblies.


Dynamic Assembly Sequence Point Dynamic Type Argument Type Transient Module 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Other DefineType() overrides allow you to specify the packing size or the total size of the type, but I won’t cover those scenarios in this book.Google Scholar
  2. 2.
    See the BuildProperties() method in the code sample for this chapter for the code to override the base property’s methods.Google Scholar
  3. 3.
    Note that OpCodes is not an enumeration; I assumed this at first glance, which really left me confused the more I dug into this.Google Scholar
  4. 4.
    I’ve seen no difference in the resulting assemblies between the two techniques. Personally, I like using Emit() to call methods, as I usually don’t call vararg methods on a regular basis, so it saves on some coding keystrokes.Google Scholar
  5. 5.
    This leads to an interesting proposal of writing all of your CIL code via the Emitter classes in the.NET language of your choice so you don’t have to figure out what.maxstack should be.Google Scholar
  6. 6.
    In the next chapter, you’ll see an ideal candidate for such a service: method interception.Google Scholar
  7. 7.
    Please refer to the Source Code description at the end of the section “Debugging Dynamic Assemblies” to see where the code snippets in this section come from.Google Scholar
  8. 8.
    There is a version of DefineDynamicModule() to emit debug information for transient modules, which I’ll cover at the end of this chapter.Google Scholar
  9. 9.
    I find it odd that the Signature property is not defined on MethodBase or Methodlnfo; if it were, the need for this method and its contained type casting would be unnecessary.Google Scholar
  10. 10.
    This information was found by digging around in mscorlib.dll using reverse-engineering tools; it’s not something you’d find by using the.NET SDK.Google Scholar

Copyright information

© Jason Bock 2002

Authors and Affiliations

  • Jason Bock

There are no affiliations available

Personalised recommendations