Emitting MSIL with Reflection
- The Imminent Potential of Microsoft Intermediate Language (MSIL)
- Brief Overview
- Emitting Dynamic Assemblies
- Creating a "Hello World" Emitter
Web services sit squarely at the cornerstone of Microsoft's marketing initiative for .NET. Web services offer a promise of shared information, cross-platform application integration, and facilitated workflow solutions. These concepts are targeted at business managers, and businesses should be enthusiastic about this technology. However, among technologists the most animated discussions are on the subject of reflection and emitting.
.NET reflection supports emitting Microsoft Intermediate Language (MSIL)an intermediate language between assembly and a .NET language like C#. The System.Reflection.Emit namespace contains classes that support emitting dynamic assemblies that contain MSIL, and on top of the System.Reflection.Emit namespace is the CodeDom technology (the System.CodeDom and System.CodeDom.Compiler namespaces). The CodeDom allows programmers to emit and compile code such as Visual Basic .NET and C#.
Why do programmers find this technology so compelling? I think the reason is that it gets the imagination and the creative juices flowing. We imagine creating software that's smart, that evolvesdubbed adaptive software. Perhaps the software evolves based on usage patterns or the acquisition of data, but it evolves.
It may be too early to know for sure whether .NET will advance the capability of smart programs, but the notion of adaptive software is a compelling conversation among techno-weenies (a Tom Clancy term for geeks).
One thing for sure is that .NET has a lot to offer. There's a promise of integrated business solutions using open standards, and for technologists a promise of access to cool technologies. In this short article, I'll introduce what Harry Pierson (of Microsoft's National Technology Team) calls writing code generators and I call writing emitters: how classes in the Reflection.Emit namespace can be used to write MSIL at runtime.