Hi, On Mon, Apr 18, 2011 at 8:07 PM, ShdNx <[email protected]> wrote: > The solution must be very trivial, but I just cannot see it.
It's indeed pretty simple when you wrap your head around how generics are encoded. I suggest you have a look at: https://github.com/jbevain/cecil/blob/master/Test/Mono.Cecil.Tests/ImportCecilTests.cs Basically you can do: // get the definitions TypeDefinition nullable = ...; MethodDefinition has_value_def = nullable.Methods.Single (m => m.Name == "get_HasValue"); MethodDefinition get_value_def = nullable.Methods.Single (m => m.Name == "get_Value"); // create the proper generic forms MethodReference has_value_for_int = has_value_def.MakeGeneric (module.TypeSystem.Int32); MethodReference get_value_for_int = get_value_def.MakeGeneric (module.TypeSystem.Int32); // import them in our target module MethodReference has_value_int = module.Import (has_value_for_int); MethodReference get_value_int = module.Import (get_value_for_int); MakeGeneric comes from the Cecil test suite. I have to find a better name better moving it to Cecil.Rocks. Of course this has been made verbose on purpose, but the essential is here. Jb -- -- mono-cecil
