.NET Reflection: Find Used Types

I pull my hair out trying to solve it. What I'm trying to do is create a “map” of how objects are used in some code I'm working on. Think of it as an advanced search. The easiest way to show this is with an example:

public class MasterClass
{
    Type1 type1;
    Type2 type2;
    Type3 type3;
    void InitializeData()
    {
        type1 = new Type1(this);
        type2 = new Type2(this);
        type3 = new Type3(this);
    }
}

public class Type1
{
    private MasterClass _master;
    public Type1(MasterClass master)
    {
        _master = master;
    }
    public void Something()
    {
        //use _master.type2 and _master.type3 here
    }
}

public class Type2
{
    private MasterClass _master;
    public Type2(MasterClass master)
    {
        _master = master;
    }
    public void Something()
    {
        //use _master.type3 here
    }
}

public class Type3
{
    private MasterClass _master;
    public Type3(MasterClass master)
    {
        _master = master;
    }
    public void Something()
    {
        //use _master.type1 and _master.type2 here
    }
}

What I'm trying to do is get a mapping or report, which in the example example will give something like:

Type1 used: {Type3}

Type2 used: {Type1, Type3}

Type3 used: {Type1, Type2}

If I can get it in the dictionary, then I'm at home. :-)

What I tried:

, , , IL, . , , , , , .

Reflector &/|| Resharper, , .

?

+5
4

. MethodInfo, PropertyInfo, FieldInfo .. :

  • (get set)
  • ( )

IL ResolveMethod , , , MethodInfo , .

EDIT:

" " Visual Studio, direct. (: method1 method2 method2 method3 - , 1 3), .

+3

NDepend , , . .

+7
0
0

All Articles