看基类被那几个类继承了

using System;
using System.Reflection;
using System.Linq;
 
public class BaseClass
{
}
 
public class DerivedClass1 : BaseClass
{
}
 
public class DerivedClass2 : BaseClass
{
}
 
class Program
{
    static void Main()
    {
        Type baseType = typeof(BaseClass);
        Assembly assembly = Assembly.GetExecutingAssembly();
 
        var derivedTypes = assembly.GetTypes()
            .Where(t => t.IsSubclassOf(baseType));
 
        foreach (var type in derivedTypes)
        {
            Console.WriteLine(type.Name);
        }
    }
}

  

posted @ 2024-04-25 11:52  gatran  阅读(3)  评论(0编辑  收藏  举报