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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Reference
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.
See the BuildProperties() method in the code sample for this chapter for the code to override the base property’s methods.
Note that OpCodes is not an enumeration; I assumed this at first glance, which really left me confused the more I dug into this.
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.
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.
In the next chapter, you’ll see an ideal candidate for such a service: method interception.
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.
There is a version of DefineDynamicModule() to emit debug information for transient modules, which I’ll cover at the end of this chapter.
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.
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.
Rights 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