Inject Method with Mono.Cecil
问题 How can I inject a custom method into a .net assembly using mono.cecil, and then call it in the entrypoint? I like to do this to implement security methods after the binary is built. 回答1: To inject method you need to get the type you want to add it the method and then add a MethoDefinition . var mainModule = ModuleDefinition.ReadModule(assemblyPath); var type = module.Types.Single(t => t.Name == "TypeYouWant"); var newMethodDef= new MethodDefinition("Name", MethodAttributes.Public, mainModule