diff --git a/SkillUpgrades/SkillUpgradeSettings.cs b/SkillUpgrades/SkillUpgradeSettings.cs index 34e52f7..059f1e8 100644 --- a/SkillUpgrades/SkillUpgradeSettings.cs +++ b/SkillUpgrades/SkillUpgradeSettings.cs @@ -97,7 +97,7 @@ static SkillUpgradeSettings() { Fields = new Dictionary(); - foreach (Type t in typeof(SkillUpgradeSettings).Assembly.GetTypesSafely().Where(t => t.IsSubclassOf(typeof(AbstractSkillUpgrade)) && !t.IsAbstract)) + foreach (Type t in AbstractSkillUpgrade.GetAvailableSkillUpgradeTypes()) { foreach (FieldInfo fi in t.GetFields(BindingFlags.Public | BindingFlags.Static)) { diff --git a/SkillUpgrades/SkillUpgrades.cs b/SkillUpgrades/SkillUpgrades.cs index c52ff85..fbee6eb 100644 --- a/SkillUpgrades/SkillUpgrades.cs +++ b/SkillUpgrades/SkillUpgrades.cs @@ -34,7 +34,7 @@ public override void Initialize() instance.Log("Initializing"); DebugMod.AddActionToKeyBindList(() => { ApplyGlobalToggle(!GS.GlobalToggle); RefreshMainMenu(); }, "Global Toggle", "SkillUpgrades"); - foreach (Type t in typeof(SkillUpgrades).Assembly.GetTypesSafely().Where(x => x.IsSubclassOf(typeof(AbstractSkillUpgrade)))) + foreach (Type t in AbstractSkillUpgrade.GetAvailableSkillUpgradeTypes()) { AbstractSkillUpgrade skill = (AbstractSkillUpgrade)Activator.CreateInstance(t); _skills.Add(skill.Name, skill); diff --git a/SkillUpgrades/SkillUpgrades.csproj b/SkillUpgrades/SkillUpgrades.csproj index d3d9938..12a625c 100644 --- a/SkillUpgrades/SkillUpgrades.csproj +++ b/SkillUpgrades/SkillUpgrades.csproj @@ -4,7 +4,7 @@ net472 SkillUpgrades SkillUpgrades - 0.9.0 + 0.9.2 true false latest diff --git a/SkillUpgrades/Skills/AbstractSkillUpgrade.cs b/SkillUpgrades/Skills/AbstractSkillUpgrade.cs index c795c51..074f10b 100644 --- a/SkillUpgrades/Skills/AbstractSkillUpgrade.cs +++ b/SkillUpgrades/Skills/AbstractSkillUpgrade.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; using JetBrains.Annotations; using Modding; using SkillUpgrades.Util; @@ -135,5 +138,22 @@ protected virtual string FormatLogMessage(string message) } private string FormatLogMessage(object message) => FormatLogMessage(message?.ToString() ?? "null"); #endregion + + /// + /// Returns an enumerable over the Skill Upgrades in this assembly. + /// + public static IEnumerable GetAvailableSkillUpgradeTypes() + { + Assembly asm = typeof(AbstractSkillUpgrade).Assembly; + // TODO - take GetTypesSafely from MAPI when I can + try + { + return asm.GetTypes().Where(type => type.IsSubclassOf(typeof(AbstractSkillUpgrade)) && !type.IsAbstract); + } + catch (ReflectionTypeLoadException ex) + { + return ex.Types.Where(type => type is not null && type.IsSubclassOf(typeof(AbstractSkillUpgrade)) && !type.IsAbstract); + } + } } }