Emitted.Net

Project page: https://bitbucket.org/lassevk/emitted.net.

Overview

The Emitted.Net project was spawned to host a piece of my code that I use a lot in projects that deal with dynamic code generation. To emit dynamic code in .NET, you need to use some general classes and methods in .NET that puts the burden of knowledge of what goes together on the programmer, and I felt that I often made mistakes because of this.

Emitted.Net helps with this by adding extension methods to the .NET ILGenerator class that allows the programmer to seemingly write IL code directly in the program, with intellisense to help with what opcodes supports which parameter type combinations.

Additionally, the library adds helper routines and classes that simplify some of the grunt work of dealing with dynamic code, defining types and members.

The class library is written in C# 3.0, for .NET 3.5 and 4.0, in a Visual Studio 2010 solution.

Example

var method = new DynamicMethod<Func<int, int, int>>("add"); // strongly typed
method.IL
    .ldarg_0()
    .ldarg_1()
    .add()
    .ret();
var methodDelegate = method.CreateDelegate(); // strongly typed to Func<int, int, int>
var sum = methodDelegate(17, 42); // return 59

Releases

The software has not yet been officially released with any specific version tag, and is to be considered in beta-stage. It has been made available on http://bitbucket.org but will be migrated to CodePlex in the near future, and a proper release plan will be made. For now, the source code is available.