Files
Fishing2/Assets/Scripts/Utils/Reflection.cs
2025-05-10 12:49:47 +08:00

39 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace NBF
{
public static class Reflection
{
static Assembly _assembly;
static Reflection()
{
_assembly = AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == "Assembly-CSharp");
Types = _assembly.GetTypes();
}
public static Type[] Types { get; private set; }
/// <summary>
/// 获取所有非抽象的派生类
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static List<Type> GetAllNonAbstractDerivedTypes<T>()
{
Type baseType = typeof(T);
Assembly assembly = Assembly.GetAssembly(baseType);
List<Type> derivedTypes = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(baseType))
.ToList();
return derivedTypes;
}
}
}