This project is read-only.

Getting Started

Topics: Metadata Model
Jun 17, 2009 at 11:07 AM

First I must say this is a great set of tools to look into IL code. I have created a visitor to look into all elements of an assembly. Specifically I am interested if any function, member variable is used which is defined in another assembly to track changes in them. For this I found it very easy to look into all members but I did not find a way so far to get my hands on the declaring assembly:

        public void Visit(IFieldDefinition fieldDefinition)
           Console.WriteLine("Member {0} in assembly {1}", fieldDefinition.Type.ToString(), fieldDefinition.Name);

I do not only want the class name but also the declaring assembly name. Is there any easy way to do this by default. In the debugger I see it but the members of the class are internal.
The same is true I guess if I look for field get/set calls to a specific type. 
  Alois Kraus
Jun 17, 2009 at 5:36 PM

The ToString() methods are specific to the implementations of the metadata model and should not be relied on. Instead, use the routines such as MemberHelper.GetMemberSignature, which has various options for formatting the name. See also the SignatureFormatter class, which is used under the covers by MemberHelper and which can be subclassed and specialized to format member signatures in an application/language specific way.

You can get hold of the assembly that declares the field by running up the containment links. TypeHelper.GetContainingUnit(field.ContainingType) should to the trick for you.