G
G
Goldywhite2011-06-03 10:26:38
Programming
Goldywhite, 2011-06-03 10:26:38

How to call a virtual method in C# from IL?

Good afternoon.
Initial data: there is a MethodInfo of a virtual method, for example, obtained from the interface
Task: it is necessary to assemble a function that calls virtual methods with the same signature using the calli
instruction implements a virtual function lookup and makes a call?
For example, if the method is non-virtual and the address of the method, for example, is passed as the first argument:

ldftn calli <br/>
можно заменить на<br/>
<code>ldarg.0<br/>
conv.i<br/>
calli <br/>
В данном случае адрес метода получается следующим образом: <br/>
<code>MethodInfo m;<br/>
var ptr = m.MethodHandle.GetFunctionPointer()</code></code>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ap3rus, 2011-06-03
@ap3rus

Try using callvirt www.simple-talk.com/community/blogs/simonc/archive/2010/11/05/95541.aspx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question