Title CIL Programming: Under the Hood of .NET
Subject .NET
ISBN 1590590414
Author Jason Bock
Publisher APress
UK Price £35.5
Our Price £29.98
You Save 16%
User Level Beginner - Advanced

   
 
For the most part, .NET developers use a high-level language, such as C# or VB .NET, to develop their systems. However, the core language of .NET is the Common Intermediate Language, or CIL. This language is the language of .NET - developers can use CIL to do whatever is allowed by the .NET specifications, which is not the case for C# and VB .NET. Although it is unlikely that the majority of .NET developers will create their assemblies in CIL, understanding how CIL works will give them a deep, language-independent insight into the core parts of .NET. Furthermore, such knowledge is essential for creating dynamic types, a powerful part of the .NET Framework.

In CIL Programming: Under the Hood of .NET, Jason Bock covers the essentials of programming in CIL. First, Bock discusses the basics of what .NET assemblies are and how manifests fit into the picture. He then shows how to create assemblies in .NET - including the ilasm directives and CIL opcodes, and how these are used to define assemblies, classes, field, methods, and method definitions. Bock also covers how C#, VB .NET and other non-Microsoft languages emit CIL and how they differ. Finally, he reveals how developers can create dynamic assemblies at runtime via the Emitter classes.

After reading CIL Programming: Under the Hood of .NET, developers will have a better understanding of the CIL and how to program directly into it. A must-have on every .NET developer's desk!

Table of Contents:

Chapter 1 Language Interoperability
Language Interoperability in Action
Language Interoperability in Theory
Language Interoperability in Practice
Conclusion

Chapter 2 ilasm Directives and Attributes
General Assembly ilasm
* Defining the Assembly
* Defining the Modules
* Defining the UI
* Concurrent Assembly Execution
* Defining Data Segments
Type-Specific Directives
* Defining the Type
Adding Fields to a Type
* Field Scope
* Field Initialization
* serializable Redux
Adding Methods to Types
* Type and Instance Methods
* Method Implementation Details
* Calling Conventions
* Passing Arguments
* Unmanaged Calls
* Type and Instance Initializers
* beforefieldinit Redux
* Exporting Methods
* Method Body Directives
Defining Properties in Types
Adding Events to Types
Conclusion

Chapter 3 CIL Opcodes
Basic Stack Information
Opcode Essentials
Basic Opcodes
* Using Local Variables
* Conversions
* Using Method Arguments
* Using Type Fields
Basic Operations
* Arithmetic Operations
* Binary Operations
* Comparison Operations
Object Instructions
* Creating Type Instances
* Calling Methods
* Constructors
* Unmanaged Method Calls
* Method Pointers
* Boxing, Unboxing, and Value Type Indirection
* Type Casting
* Array Manipulation
* Memory Manipulation
* String Manipulation
Controlling Code Flow
Handling Exceptions
Opcode Miscellanea
* Variable Argument Lists
* .maxstack Calculations
* Pointer Prefixes
* Method Jumps
Conclusion

Chapter 4 ilasm and CIL in Practice
Generating Random Numbers
Designing the Essentials
Implementing the Essentials
* Stubbing Out the Delegate
* Field Definitions
* Event Methods
* Constructors
* Creating the Properties
* Implementing Generate()
* Implementing GenerateViaDelegate()
* Implementing GenerateViaEvent()
* Generating the RIG Assembly
Designing the Test Harness
Implementing the Test Harness
* Referencing Assemblies for UI Design
* Defining UI Components
* Initializing the Form
* Calling Generate()
* Calling GenerateViaDelegate()
* Calling GenerateViaEvent()
* Generating the RIGTestClient Assembly
Conclusion

Chapter 5 Debugging CIL
Debug Builds
The Command-line Tool: cordbg.exe
* cordbg Basics
* Watching Register Values and Native Instructions
* Setting Breakpoints
* Modes
* Recording and Using cordbg Scripts
The GUI Tool: dbgclr.exe
* Debugging Windows
* Saving the Solution
* Debugger Differences
Debugging In-Process Assemblies
* DLLs in dbgclr
* DLLs in cordbg
Registry Control
Verifying Assemblies
Debugging Compiled Programs
* Preventing Recompilation
Conclusion

Chapter 6 .NET Languages and CIL
Debug and Release Builds
* The C# Implementation
* The VB .NET Implementation
* The Component Pascal Implementation
* Commentary
Language Constructs
* VB .NET's With Statement
* Implementing Interface Methods
* On Error Resume Next, or How to Create a Lot of CIL
* Active Objects
Language Interoperability: The Real Story
* Inheritance with Oberon .NET Types
* Overloaded and Overridden Methods
* The Other Property
* Overloading Methods in CIL
Conclusion

Chapter 7 Emitting Types
Applying CIL
Emitter Basics
* Defining the Essentials
* Creating Assemblies
* Building Types
* Adding Fields
Emitting Methods
* Adding Methods
* Implementing Methods
* Exception Handling
Persisting the Results
* Baking Types
* Transient-Only Assemblies
* Persistent-Only Assemblies
* Transient, Persistent Assemblies
Beyond the Basics
* Setting Entry Points
* Adding Attributes
* Modifying Method Parameter Information
Debugging Dynamic Assemblies
* Emitting Debug Information
* Adding to the Symbol Writer
* Reloading the Assembly
* Where's the Target IL File?
* Creating the DebugFile Class
* Debugging Transient Modules
Conclusion

Chapter 8 Dynamic Proxies in .NET
Separating Concerns
Functional Specifications
Class Design and Method Call Conditions
* Receiving a Notification before Method Invocation
* Receiving a Notification after Method Invocation
* When Method Invocations Go Bad
* Proxy Call Flow
Implementing Proxy Creation
* Preconditional Checks
* Caching Types, Modules, and Assemblies
* Defining the Constructors
* Implementing the Interfaces
* Invoking Target Methods
* Setting Up the Method Hooks
Testing the Solution
* Loading the Form
* Creating Proxies
* Type Inspection
Contexts and .NET
* Dynamic Proxies and Contexts
Conclusion

Chapter 9 CIL Tips
Be CLS-Compliant Aware
Use Verification Tools
Comments and Code Regions
Stay Location Savvy When Emitting Assemblies
Final Thoughts

Appendix A The Future of CIL
Generics in CIL
Extended IL
Inline CIL

Appendix B .NET Languages
Book Cover