The System.Reflection.Emit namespace provides classes to create dynamic assemblies at runtime. It allows compilers and tools to emit MSIL, execute it and store it to a disk. Although Emit is a powerful tool, it is also extremely hard to use.

Let us take a look at the following example, which demonstrates the "normal" way of emit programming:

HelloWorld.cs <% ..\..\..\Examples\CS\Reflection.Emit\HelloWorldnormal.cs %>

Note that the Emit method takes one parameter as an OpCode and optionally another one, which does not depend on the current operation context. So, this way is not entirely type safe.

Fortunately, there is an alternative way. BLToolkit provides a helper class, EmitHelper, which can make your life a little bit easy. It contains typed wrapper methods for almost all emit commands and allows writing source code that looks similar to MSIL.

The following examples show how to use the EmitHelper class with C#, VB.NET, and C++/CLI.

HelloWorld.cs <% ..\..\..\Examples\CS\Reflection.Emit\HelloWorld.cs %> Cool!!! Isn't it?

HelloWorld.vb <% ..\..\..\Examples\VB\Reflection.Emit\HelloWorld.vb %> HelloWorld.cpp <% ..\..\..\Examples\Cpp\HelloWorld.cpp %>