I don't know about anything that would disassemble a whole in-memory assembly into text. And I don't know how could you save an in-memory assembly to disk to use a file-based disassembler (like ildasm).
But if all you want is to find out what constant strings are used by methods, you don't need all that.
To access the IL of a method (that you have as MethodInfo
), you can use method.GetMethodBody().GetILAsByteArray()
. As the method name implies, this gives you a byte[]
, which is not easy to work with. But you can use Jb Evain's Mono.Reflection to do the hard work for you (despite the name, it's not really related to Mono and can be used from normal .Net too).
The only step remaining is to realize that constant strings are accessed using the ldstr
instruction, so that's what we need to look for.
Knowing all this, finding the constant strings used by a method is as simple as:
method.GetInstructions().Where(i => i.OpCode == OpCodes.Ldstr).Select(i => (string)i.Operand)