Skip to content

Instantly share code, notes, and snippets.

@SimonCropp
Created February 20, 2012 00:06
Show Gist options
  • Save SimonCropp/1866672 to your computer and use it in GitHub Desktop.
Save SimonCropp/1866672 to your computer and use it in GitHub Desktop.
var path = @"F:\Code\CecilTest\TargetLibrary\bin\Debug\TargetLibrary.dll";
var moduleDefinition = ModuleDefinition.ReadModule(path);
var typeDefinition = moduleDefinition.Types.First(x => x.Name.EndsWith("Class1"));
var voidType = Type.GetType("System.Void");
var voidTypeReference = moduleDefinition.Import(voidType);
var methodDefinition = new MethodDefinition(".ctor", MethodAttributes.Public, voidTypeReference);
typeDefinition.Methods.Add(methodDefinition);
moduleDefinition.Write(path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment