using System; using System.Collections.Generic; using System.Linq; using CalamityMod.Particles; using Terraria.ModLoader; using Terraria.ModLoader.Core; namespace CalamityMod { [Obsolete($"This is kept for {nameof(GeneralParticleHandler)}. Consider use ILoadable or ModType If possible.")] public static class ReflectionHelper { public static IEnumerable GetEveryModsTypes() { return ModLoader.Mods.SelectMany(mod => AssemblyManager.GetLoadableTypes(mod.Code)); } public static bool IsSubclass(Type baseType, Type type, bool includeBaseType) { return type.IsSubclassOf(baseType) && !type.IsAbstract && (!includeBaseType && type != baseType); } // TODO: Consider replacing with ModType? public static void IterateEveryModsTypes(Action action, bool includeBaseType = false) { // WHY???? if (action is null) return; Type baseType = typeof(T); var types = GetEveryModsTypes().Where(t => IsSubclass(baseType, t, includeBaseType)); foreach (var type in types) { action.Invoke(type); } } } }