tags:

views:

62

answers:

1

Hi,

Whats the easiest way to traverse a methodinfo in c#?

I want to traverse the method body and find field-references and such and retrieves the types.

In System.Reflection there is:

mi.GetMethodBody().GetILAsByteArray()

which is kinda low-level and would require "some" work before I would be able to traverse the body.

I know Cecil exists, but there's a problem in loading an in memory assembly with cecil. The assembly i'm working with is't always "on disk" it can be an in memory assembly compiled from eg. Boo, and I wan't a clean solution without writing the assembly temporary to disk.

What other alternatives is there out there for this?

+5  A: 

This thing should help: Reflection based CIL reader. It operates on byte array obtained by calling GetILAsByteArray()

desco
Thanks, that should do it. Must have missed that one when googled for a solution.
Marcus
At least you googled before asking. Not like so many here on the site ;-)
Yves M.
If anyone from the mono-team is reading this, there is a bug or something in the runtime:https://bugzilla.novell.com/show_bug.cgi?id=628660
Marcus