Reflection.Emit help request

J

John

I am trying to figure out how to translate the following CIL call into
an Emit statement.

In CIL it is:
IL_004c: callvirt instance class [System.Data]System.Data.DataRow
[System.Data]System.Data.DataRowCollection::get_Item(int32)

The C# equivilant is as follows:
MyDataRowCollection[0];

I thought it would be something like:
ilGenerator.Emit(OpCodes.Callvirt,
typeof(DataRowCollection).GetProperty("Item").GetGetMethod());

However, I can't figure out how to pass in the [Int32] value into the
Emit call to make it like the CIL. Can anyone assist? What is the
proper Emit call in this scenerio? I am a little stumped, obviously I
am doing something wrong, but not sure what it is, exactly.

I would appreciate any assistance.

TIA
 
N

Nicholas Paldino [.NET/C# MVP]

John,

The CLR is stack-based, meaning that the parameters are taken from the
stack.

If you write your code in C# and then compile it and look at the IL, you
will see that the parameter is placed on the stack before the call and then
the method parameters will be taken off the stack.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top