Hi Jair

On May 29, 9:36 pm, "Jair Cazarin" <[EMAIL PROTECTED]> wrote:

[...]
> The only problem is that I'm calling the Invoke method for:
>
> callvirt !0 [System.Core]System.Func`1::Invoke()

It looks like you are acquirering a MethodReference object from the
generic type itself and not an appropriate instance of the generic
type.

(Disclaimer: I am not near my work pc, so the following is from memory
and complete untested.) A template for your code may look like this:

  TypeReference func =
assembly.MainModule.Import(typeof(System.Func<>));
  TypeReference tbase = ... get type reference for C.Tbase ...

  GenericInstanceType funcOfTbase = new GenericInstanceType(func);
  funcOfTbase.GenericArguments.Add(tbase); // funcOfTbase represents
the type instance Func<Tbase>

  MethodReference invokeMethod = new MethodReference("Invoke",
funcOfTbase, func.GenericParameters[0], true, false,
MethodCallingConvention.Default);

  ... add invokeMethod to the assembly member references if
necessary ...
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to