Getting IL Code for a Method

G

Guest

Hello,

With reflection, is it a way to get (in managed code) the IL Code of a
method ?
I would like to retrieve for a Method, all the called inner Method.

I know how to Emit IL Code in assembly, but I can't find the reverse
possibility.
The only think I have found is the MethodHandle function of MethodInfo
class, that theorically return the metadata, but I can't find a way to go
further.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Ludovic,

In .NET 2.0, you will be able to call the GetMethodBody method on the
MethodInfo instance and get a MethodBody instance which will allow you
access to the IL as a byte array.

Hope this helps.
 
G

Guest

Thanks for this response.

Unfortunatly, I work on .Net 1.1.
Is it a way to retrieve this byte array by another way ?

Thanks.


Nicholas Paldino said:
Ludovic,

In .NET 2.0, you will be able to call the GetMethodBody method on the
MethodInfo instance and get a MethodBody instance which will allow you
access to the IL as a byte array.

Hope this helps.


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

Ludovic DE FREITAS said:
Hello,

With reflection, is it a way to get (in managed code) the IL Code of a
method ?
I would like to retrieve for a Method, all the called inner Method.

I know how to Emit IL Code in assembly, but I can't find the reverse
possibility.
The only think I have found is the MethodHandle function of MethodInfo
class, that theorically return the metadata, but I can't find a way to go
further.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Ludovic,

Unfortunately, without opening up the assembly yourself and parsing
through it, I don't know if there is a way to get the body of the method.


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

Ludovic DE FREITAS said:
Thanks for this response.

Unfortunatly, I work on .Net 1.1.
Is it a way to retrieve this byte array by another way ?

Thanks.


Nicholas Paldino said:
Ludovic,

In .NET 2.0, you will be able to call the GetMethodBody method on the
MethodInfo instance and get a MethodBody instance which will allow you
access to the IL as a byte array.

Hope this helps.


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

in
message news:[email protected]...
Hello,

With reflection, is it a way to get (in managed code) the IL Code of a
method ?
I would like to retrieve for a Method, all the called inner Method.

I know how to Emit IL Code in assembly, but I can't find the reverse
possibility.
The only think I have found is the MethodHandle function of MethodInfo
class, that theorically return the metadata, but I can't find a way to
go
further.

Thanks.
 

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