static void Main()
{
//LoadAssemblies();
Func<Type, string> classnameAndBase = null;
classnameAndBase = t => "-" + t.FullName + ((t.BaseType != typeof(object)) ? classnameAndBase(t.BaseType) : string.Empty);
//定义查询,在当前AppDomain中加载的所有程序集中查找从exception派生的所有public类型
var exceptionTree = (from a in AppDomain.CurrentDomain.GetAssemblies()
from t in a.GetExportedTypes()
where t.IsClass && t.IsPublic && typeof(Exception).IsAssignableFrom(t)
let typeHierarchTemp = classnameAndBase(t).Split('-').Reverse().ToArray()
let typeHierarchy = string.Join("-", typeHierarchTemp, 0, typeHierarchTemp.Length - 1)
orderby typeHierarchy
select typeHierarchy
).ToArray();
Console.WriteLine("{0} 个异常类", exceptionTree.Count());
foreach (string s in exceptionTree)
{
string[] x = s.Split('-');
//根据基类型的数量进行缩进
Console.WriteLine(new string(' ', 3 * (x.Length - 1)) + x[x.Length - 1]);
}
Console.ReadKey();
}