This project is read-only.

Obtain a IMethodReference from IInstruction.Value

Nov 25, 2009 at 5:03 AM

I have a simple bit of code (mostly from Jason Haley's article) that wraps Reflector.exe. I am trying to get the information found in Analysis' pane's "Used By" and "Instantiated By" items. In abbreviated form (no curly braces, etc) the code goes like this:

foreach (IModule module in assembly.Modules)
    foreach (ITypeDeclaration typeDeclaration in module.Types)
       foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Methods)
          IMethodBody methodBody = methodDeclaration.Body as IMethodBody;
          foreach (IInstruction instruction in methodBody.Instructions)
         /* appropriate code to find call, calli, callvirt, and newobj
            statements  and for them obtain instruction.value*/

All of this works as expected. The problem arises from the fact that  the Target of the statements is not a fully qualified name as illustrated:

     Call to : String.get_Length() : Int32
     Call to : String.Trim() : String
     Instance: StringBuilder..ctor() : Void
     Call to : StringLogicalComparer.CompareNumbers(String, String, Int32, Int32&) : Int32


Obviously I need the fully qualified names to filter out calls to the .Net libraries and to distinguish between my own Namespaces, etc.

What I seem to need is a way to obtain the appropriate IMethodReference from Reflector for the Target of the calls and newobj statements.

Is there any hope of getting what I need? It is very frustrating to be so close yet so far away.

Thanks for any help you can give me.

    Jim Parsells