473,513 Members | 2,323 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.Reflection.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.GetILGenerator();
methodIL.Emit(OpCodes.Ldc_I4, 1);
methodIL.Emit(OpCodes.Ret)

Thanks.
Nov 17 '05 #1
2 3641
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**************@TK2MSFTNGP12.phx.gbl...
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 static int Rule001() { return 1; }
==>
ILGenerator methodIL = ruleMethod.GetILGenerator();
methodIL.Emit(OpCodes.Ldc_I4, 1);
methodIL.Emit(OpCodes.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.Reflection.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.GetILGenerator();
methodIL.Emit(OpCodes.Ldc_I4, 1);
methodIL.Emit(OpCodes.Ret)*
Thanks.

Have you looked at the Microsoft.CSharp.CSharpCodeProvider 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
1971
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...
2
2231
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...
7
9934
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
2502
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...
4
1850
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...
7
6517
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...
0
1158
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...
0
1539
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...
8
3847
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...
0
7391
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,...
0
7553
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...
1
7120
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...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
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...

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.