Reflection.Emit help request

  • Thread starter Thread starter John
  • Start date Start date
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
 
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.
 
Back
Top