Get the IL out of a method?

B

Bilz

Hi all,

I am curious if there is any way to get the IL from a given method at
runtime? I know about ILDasm.exe, but I was hoping to peek into the
assembly and get the actual IL.

In practice, I want to compile code on the fly using the
CSharpCodeProvider and pull out the IL to store in an XML file.

It seems like I should be able to do this, but I am just not finding
the right classes to do this.

Thanks,
B
 
J

Jon Skeet [C# MVP]

I am curious if there is any way to get the IL from a given method at
runtime? I know about ILDasm.exe, but I was hoping to peek into the
assembly and get the actual IL.

In practice, I want to compile code on the fly using the
CSharpCodeProvider and pull out the IL to store in an XML file.

It seems like I should be able to do this, but I am just not finding
the right classes to do this.

Have a look at the MethodBody class - to get a MethodBody, first get a
MethodInfo and then call GetMethodBody.

Jon
 

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