473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Reflection.Emit help request

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").GetG etMethod());

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
Oct 10 '07 #1
1 1418
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"John" <pl*********@use.netwrote in message
news:eR**************@TK2MSFTNGP03.phx.gbl...
>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").GetG etMethod());

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
Oct 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nigel Sampson | last post by:
ey all, I'm in the process of creating a method of tracking whenever an objects properties are changed. Since its not possible to alter existing types I decided to used a proxy generated using...
0
by: john | last post by:
Is there a way to use the Reflection.Emit namespace classes to load an existing assembly, then modify it by emitting IL to the loaded assembly, then saving the modified assembly back to a file? ...
7
by: Mark Miller | last post by:
I am using Reflection.Emit to dynamically build a class. A method of the class to be built requires a Parameter of type "Type". But I don't know how to use Emit to pass a call of "typeof()" to the...
3
by: John Arthur | last post by:
Hi, I am reading about Reflection.Emit and I can't really imagine a real situation where I can use this. Can someone give me an example that can't be done without Reflection or an example of...
2
by: Striped | last post by:
Is there any tool to convert source code, e.g. of a C# method, to opcodes being used in System.Reflection.Emit? It's a real pain to do that manually, especially for big pieces of code. public...
3
by: ayende | last post by:
How do I use Reflection.Emit to produce code similar to this? public void bar<T>() { } public void foo<J>() { bar<J>(); }
2
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
2
by: allfyre | last post by:
Ok, to make a long story short, I'm Emitting some MSIL from a c# application. I know that THIS is the MSIL I want to be emitting: //**************************************************************...
0
by: cfatulescu | last post by:
Hello, i'm trying to reproduce a method using Reflection.Emit, everything is going well except one small thing, without all my job is done for nothing. I can not reproduce the keyword...
0
by: =?Utf-8?B?QXJ0dXJvIE1hcnRpbmV6?= | last post by:
I've been looking everywhere on how to call AddRange Method of a List<myClassfield in Reflection.Emit My code goes like this MethodInfo method =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.