473,545 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert source code to opcodes used in Reflection.Emit ?

Is there any tool to convert source code, e.g. of a C# method, to opcodes being used in System.Reflecti on.Emit? It's a real pain to do that manually, especially for big pieces of code.

public static int Rule001() { return 1; }
==>
ILGenerator methodIL = ruleMethod.GetI LGenerator();
methodIL.Emit(O pCodes.Ldc_I4, 1);
methodIL.Emit(O pCodes.Ret)

Thanks.
Nov 17 '05 #1
2 3648
Oh,
I believe the simpliest solution is to create a library and use ILDAsm on it.

"Striped" <no****@nospam. com> wrote in message news:us******** ******@TK2MSFTN GP12.phx.gbl...
Is there any tool to convert source code, e.g. of a C# method, to opcodes being used in System.Reflecti on.Emit? It's a real pain to do that manually, especially for big pieces of code.

public static int Rule001() { return 1; }
==>
ILGenerator methodIL = ruleMethod.GetI LGenerator();
methodIL.Emit(O pCodes.Ldc_I4, 1);
methodIL.Emit(O pCodes.Ret)

Thanks.
Nov 17 '05 #2
Striped wrote:
Is there any tool to convert source code, e.g. of a C# method, to
opcodes being used in System.Reflecti on.Emit? It's a real pain to do
that manually, especially for big pieces of code.

*public static int Rule001() { return 1; }
*==>
*ILGenerator methodIL = ruleMethod.GetI LGenerator();
methodIL.Emit(O pCodes.Ldc_I4, 1);
methodIL.Emit(O pCodes.Ret)*
Thanks.

Have you looked at the Microsoft.CShar p.CSharpCodePro vider class?
It derives from the System.CodeDom. Compiler namespace and that makes it
possible to dynamically compile .NET code on the fly resulting in an
assembly that could be executed.

Is this what you were looking for?

Christian
Nov 17 '05 #3

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

Similar topics

0
1975
by: Brian Loesgen | last post by:
The next San Diego .Net User Group meeting is Tuesday, November 25, 2003 at the Scripps Ranch Library. Scripps Ranch Library 10301 Scripps Lake Drive San Diego, CA 92131-1026 Please join us at 6:00 pm for pizza and networking. The meeting starts at 6:30 pm.
2
2232
by: Jean Stax | last post by:
Hi ! I am looking for a way to call IL instruction from withing C# code. I am not talking about System.Reflection.Emit sort of topics, but rather about existing C# code, where I want to call IL instruction. More specificly, I want to call "OpCodes.Nop" instruction in C# code in order to make some label for myself, which I would be able to...
7
9940
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 method. The method could look like this: public void myDynamicMethod(Type type){ //.....do something with the Type passed in....... }
3
2503
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 something that If done with Reflection.Emit will be a lot faster or something sensible. I will really appreciate your help. Thanks : John Arthur
4
1854
by: Generic Usenet Account | last post by:
In our environment we have several C++ header files that have some inline member function definitions. For some reason, I am unable to step through the source code of those member functions in my debugger (Insight debugger, which is a GUI front-end to GDB version 5.3). In fact, when I try to view the header file, all I see is assembly...
7
6521
by: Entwickler | last post by:
hello, i have the following problem. i want to write a code that enables the user to call functions from a unmanaged code .dll at running time . so i have to use the late binding . i tried the following code but it doesn't walk : Assembly assemblyInstance = Assembly.LoadFrom(@"C:\myData\UnmanagedCode.dll"); i don't know if somebody can help...
0
1164
by: Kofi | last post by:
Hi All, I have very recently inherited a project which includes a C# and SQL Server application I have to decipher and propose enhancements and new structural changes. The original developers are not available and system documentation is pretty much non-existent. Part of this application includes a module that accepts XML files which...
0
1542
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 "return" and to set it to an attribute by using Reflection.Emit. Help!!!, pls
8
3848
by: =?Utf-8?B?U2hhd24=?= | last post by:
Hi; i just started research reflection and i'm wondering if i have an empty class file can i use reflection to add member variables and attributes dynamically and then instantiate the class? What i would like to be able to do is start with and empty class, then depending on the data provided to me by a config file, add the member variables...
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.