Calling IL instruction from C# code

J

Jean Stax

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
identify while reflecting IL generated code.

So far, I found InvokeMethod methods in different classes (like
Type.InvokeMethod), but they don't seem to meet my needs.

Any ideas ?

Thanks
Jean
 
N

Nicholas Paldino [.NET/C# MVP]

Jean,

I don't understand why you want to call Nop as a label? If you reflect
on some code, it doesn't show you what op codes were executed, rather, what
is stored in the assembly. If you call Nop yourself, that won't be shown
anywhere using reflection.

What exactly are you trying to do?

If you want to make your own IL calls, then I think you would have to
create your own assembly in memory and then execute the methods on the types
in that assembly.

Hope this helps.
 
J

Jean Stax

Hi !

I wanted to create somthing that analyzes / parses IL code (IL
instructions, which are resulted from C# compillation). Now I thought
about the way to find the correspondence between the line in C# code
and IL code. Of course, one C# line maybe transkated to a couple of IL
lines (instructions). By "labeling" the C# code, I thought I would be
able to reach this correpondence.

Maybe you have some better ideas ?

Thanks.
Jean.

Nicholas Paldino said:
Jean,

I don't understand why you want to call Nop as a label? If you reflect
on some code, it doesn't show you what op codes were executed, rather, what
is stored in the assembly. If you call Nop yourself, that won't be shown
anywhere using reflection.

What exactly are you trying to do?

If you want to make your own IL calls, then I think you would have to
create your own assembly in memory and then execute the methods on the types
in that assembly.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jean Stax said:
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
identify while reflecting IL generated code.

So far, I found InvokeMethod methods in different classes (like
Type.InvokeMethod), but they don't seem to meet my needs.

Any ideas ?

Thanks
Jean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top