Project Description
MSIL Helper provides extension methods to the ILGenerator type. Intellisense friendly Reflection.Emit at last.

Instead of this:
    ILGenerator il = methodBuilder.GetILGenerator();
    il.Emit(OpCodes.Ldarg_1);
    il.Emit(OpCodes.Ldarg_2);
    il.Emit(OpCodes.Add);
    il.Emit(OpCodes.Ret);
Simply write:
    methodBuilder.GetILGenerator()
      .ldarg_1()
      .ldarg_2()
      .add()
      .ret();
Extension methods for ILGenerator.Emit that emit opcodes that take parameters filter the parameter types and lower your chances to make a mistake:
    ILGenerator il = methodBuilder.GetILGenerator();

    // This will happily compile, emit code and crash when executed
    il.Emit(OpCodes.LdStr, 42);
  
    // This will not compile
    il.ldstr(42);

Get MSIL Helper as a NuGet Package.

Last edited Feb 3, 2013 at 11:04 AM by vigrid, version 6