embed IL -in C#

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,

is it possible to embed il-code in C# ?
(much like the _asm directive used in C++).

If not, other ways to execute il-instructions ?

thnx

Chris
 
Chris,
I don't know of a way to embed IL, but you can easily create a dll assembly from il using ilasm.exe and reference it from your project. Apart from a few IL features not exposed in high level languages, why do you want to write code in MSIL?

Jackson Davis [MSFT
-
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

----- Chris wrote: ----

Hi

is it possible to embed il-code in C#
(much like the _asm directive used in C++)

If not, other ways to execute il-instructions

thn

Chri
 
You cant inline embed IL in your C# like you could with C++ and assembly. The best you can do is use the Reflection.Emit class to emit your IL into your assembly and then call it. The only thing is that you cant just emit a few lines of code, you have to create entire class, and then call a method of the class via reflection or a common interface.
 
Back
Top