Hi guys, what I did was something like this:

                    MethodInfo l = typeof(Func<>).GetMethod("Invoke");
                    MethodReference mr = assembly.MainModule.Import(l);
                    Instruction n =
methodDefinition.Body.CilWorker.Create(OpCodes.Call, get);
                    methodDefinition.Body.CilWorker.Replace(i, n);
                    methodDefinition.Body.CilWorker.InsertAfter(n,
methodDefinition.Body.CilWorker.Create(OpCodes.Callvirt, mr));

The only problem is that I'm calling the Invoke method for:

callvirt !0 [System.Core]System.Func`1::Invoke()

and not for:

callvirt !0 System.Func'1<C.Tbase>::Invoke()

Any ideas?


On Thu, May 29, 2008 at 2:17 AM, Jair Cazarin <[EMAIL PROTECTED]>
wrote:

> BTW I tried looking for the MethodCollection of generic and git fields:
>
>             TypeDefinition td =
> this.GetTypeDefinition(AssemblyFactory.GetAssembly("C.dll"), "C.Tbase");
>             TypeReference fd = assembly.MainModule.Import(td);
>             TypeReference generic =
> assembly.MainModule.Import(typeof(System.Func<>));
>             GenericInstanceType git = new GenericInstanceType(generic);
>             git.GenericArguments.Add(fd);
>
>
>
>
>
> On Thu, May 29, 2008 at 2:13 AM, Jair Cazarin <[EMAIL PROTECTED]>
> wrote:
>
>> Hi guys,
>>
>> I've something like the following code inside a type:
>>
>> publoc void m()
>> {
>>    new Text().DoSomething();
>> }
>>
>> In IL its:
>> nop
>> newobj System.Void B.Text::ctor()
>> stloc.0
>> ldloc.0
>> callvirt System.Void C:Tbase::DoSomething()                //Because Text
>> inherits from Tbase
>> nop
>>
>> And I want to replace this instruction in order to have the following
>> (TBaseFactory is property already defined):
>>
>> public void m()
>> {
>>    TBaseFactory().DoSomething();
>> }
>>
>> nop
>> call System.Func'1<C.Tbase> A.Ta::get_TBaseFactory()
>> callvirt !0 System.Func'1<C.Tbase>::Invoke()
>> stloc.0
>> ldloc.0
>> callvirt System.Void C.Tbase::DoSomething()
>> nop
>> ret
>>
>> My problem is that I dont know how to create the highlighted instruction.
>> Specifically I don't know where can I get the MethodReference for Invoke()
>> of Func'1<C.Tbase>.
>>
>> Regards.
>> --
>> Jair Cazarin Villanueva
>> http://jaircazarin.blogspot.com
>
>
>
>
> --
> Jair Cazarin Villanueva
> http://jaircazarin.blogspot.com
>



-- 
Jair Cazarin Villanueva
http://jaircazarin.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to