这是最不懒惰的答案(我只是为这个答案感到自豪:)
我没有 ReSharper,以前试过但不想买。我尝试了一个类图,但根本不实用,因为层次图跨越了世界 3 倍,而且我的笔记本电脑的屏幕没有无限宽度。所以我自然而简单的解决方案是编写一些 Windows 窗体代码来迭代程序集中的类型并使用反射将节点添加到树视图,如下所示:
请假设您在运行此代码的表单上有一个文本框、一个树形视图和其他所需的东西
//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();