Hi Jb, That solved my problem. Thanks for helping.
Regards. Niels Bergsma On May 24, 2:08 pm, Jb Evain <[email protected]> wrote: > Hey Niels, > > On Sun, May 23, 2010 at 7:59 PM, Niels <[email protected]> wrote: > > public static Tdestination InvokeHandler<Tsource, > > Tdestination>(Int32 signature, Tsource context) > > All right. > > > > > > > MethodDefinition invokeMethodDefinition = FindInvokeHandlerMethod(); > > MethodReference invokeMethodReference = > > property.DeclaringType.Module.Import(invokeMethodDefinition); > > invokeMethodReference.GenericParameters.Add(new > > GenericParameter("Tsource", attribute.DeclaringType)); > > invokeMethodReference.GenericParameters.Add(new > > GenericParameter("Tdestination", attribute.Property.PropertyType)); > > > But this doesn't seem to have the desired effect, the code results in > > the following IL instruction: > > > L_0012: call !!1 [Common]Common.LazyLoad::InvokeHandler(int32, !!0) > > > But the it should: > > > L_0015: call !!1 [Common]Common.LazyLoad::InvokeHandler<class > > BusinessEntities.Contact, class > > BusinessEntities.EmailAddress>(int32, !!0) > > > What am I doing wrong ? how can I supply the to generic types ? > > So, the issue here, is that you're adding types to the > GenericParameters collections. The GenericParameters collection holds > the definition of the generic parameters. > > For instance, in: > > > public static Tdestination InvokeHandler<Tsource, > > Tdestination>(Int32 signature, Tsource context) > > InvokeHandler has two generic parameters. > > But InvokeHandler<int, string> should be a GenericInstanceMethod, that > has two generic arguments, int, and string. > > So, if you have: > > > MethodDefinition invokeMethodDefinition = FindInvokeHandlerMethod(); > > MethodReference invokeMethodReference = > > property.DeclaringType.Module.Import(invokeMethodDefinition); > > Then invokeMethodReference should already have 2 GenericParameters, > Tsource, and Tdestination. Then you have to instantiate it: > > var invokeMethodReferenceInstance = new GenericInstanceMethod > (invokeMethodReference); > invokeMethodReferenceInstance.GenericArguments.Add (...); > invokeMethodReferenceInstance.GenericArguments.Add (...); > > Where ... are the TypeReference to BusinessEntities.Contact and to > BusinessEntities.EmailAddress. > > Then just pass invokeMethodReferenceInstance as an operand to the > call, and you're all set. > > -- > Jb Evain <[email protected]> > > -- > -- > mono-cecil -- -- mono-cecil
