Works great! Peverifies fine, but for some reason when I use the code: processor.InsertBefore(insertBefore, processor.Create(OpCodes.Ldtoken, method.Module.Import(method)));
When viewing in C# mode in Reflector it bugs out and crashes (IL mode displays fine). Anyone have any ideas on this one? Thanks again. On Nov 25, 5:33 am, Fabian Schmied <[email protected]> wrote: > >> But be careful with generics: On the Microsoft CLR, generic methods > >> closed with reference types share the same method handle; I think > >> you'll always get back the generic method definition for those via > >> GetMethodFromHandle. You need to call MakeGenericMethod on the result > >> to close the generic method if you need that. The behavior with > >> generic methods closed with value types might differ, as they have > >> their own handles. This is also an implementation detail that might > >> vary over time (or with Mono), I think, so you shouldn't rely on it, > >> but cope with it. (If required.) > > > Actually, I'd use the > > GetMethodFromHandle(RuntimeMethodHandle,Type[],Type[]) overload which > > would close the method in the specified generic context. It can deal > > with methodspecs tokens as well as memberref and method. > > Yes, you're right, this works. I was under the impression that this > was still buggy > (<https://connect.microsoft.com/VisualStudio/feedback/details/269853/lo...>), > but it has been fixed since .NET 2.0 SP 2 (I think). (Before that > service pack, that method did not work correctly.) > > Fabian -- -- mono-cecil
