这是最不懒惰的答案(我为这个答案感到骄傲:)
我没有ReSharper,之前也试过,但不想购买。我尝试了一个类图,但根本不实用,因为层次图跨越了世界3倍,而且笔记本电脑的屏幕没有无限宽度。因此,我自然而又轻松的解决方案是编写一些Windows Forms代码以遍历程序集中的类型,并使用反射将节点添加到树形视图中,如下所示:
请假设您在运行此代码的表单上有一个文本框,树视图和其他所需的东西
//Go through all the types and either add them to a tree node, or add a tree
//node or more to them depending whether the type is a base or derived class.
//If neither base or derived, just add them to the dictionary so that they be
//checked in the next iterations for being a parent a child or just remain a
//root level node.
var types = typeof(TYPEOFASSEMBLY).Assembly.GetExportedTypes().ToList();
Dictionary<Type, TreeNode> typeTreeDictionary = new Dictionary<Type, TreeNode>();
foreach (var t in types)
{
var tTreeNode = FromType(t);
typeTreeDictionary.Add(t, tTreeNode);
//either a parent or a child, never in between
bool foundPlaceAsParent = false;
bool foundPlaceAsChild = false;
foreach (var d in typeTreeDictionary.Keys)
{
if (d.BaseType.Equals(t))
{
//t is parent to d
foundPlaceAsParent = true;
tTreeNode.Nodes.Add(typeTreeDictionary[d]);
//typeTreeDictionary.Remove(d);
}
else if (t.BaseType.Equals(d))
{
//t is child to d
foundPlaceAsChild = true;
typeTreeDictionary[d].Nodes.Add(tTreeNode);
}
}
if (!foundPlaceAsParent && !foundPlaceAsChild)
{
//classHierarchyTreeView.Nodes.Add(tn);
}
}
foreach (var t in typeTreeDictionary.Keys)
{
if (typeTreeDictionary[t].Level == 0)
{
classHierarchyTreeView.Nodes.Add(typeTreeDictionary[t]);
}
}
StringBuilder sb = new StringBuilder();
foreach (TreeNode t in classHierarchyTreeView.Nodes)
{
sb.Append(GetStringRepresentation(t, 0));
}
textBox2.Text = sb.ToString();