Skip to main content
  • 93 Accesses

Abstract

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.95
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 49.95
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Reference

  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. See the BuildProperties() method in the code sample for this chapter for the code to override the base property’s methods.

    Google Scholar 

  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. 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. 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. In the next chapter, you’ll see an ideal candidate for such a service: method interception.

    Google Scholar 

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

Download references

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2002 Jason Bock

About this chapter

Cite this chapter

Bock, J. (2002). Emitting Types. In: CIL Programming: Under the Hood™ of .NET. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4302-0845-7_7

Download citation

  • DOI: https://doi.org/10.1007/978-1-4302-0845-7_7

  • Publisher Name: Apress, Berkeley, CA

  • Print ISBN: 978-1-4302-5156-9

  • Online ISBN: 978-1-4302-0845-7

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics