diff --git a/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs b/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs index f98fc0ea..4a9c40d0 100644 --- a/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs @@ -166,7 +166,7 @@ public abstract class ModdedOptionMemberAttribute(string? memberName, Type? hold { flags |= BindingFlags.Instance; - var canSearchPrivates = type.GetCustomAttribute() != null; + var canSearchPrivates = type.IsDefined(); if (canSearchPrivates) flags |= BindingFlags.NonPublic; @@ -175,7 +175,7 @@ public abstract class ModdedOptionMemberAttribute(string? memberName, Type? hold foreach (var method in type.GetMethods(getterFlags)) { - if (method.GetParameters().Length > 0 || (method.GetCustomAttribute() == null && method.Name != "GetInstance")) + if (method.GetParameters().Length > 0 || (method.IsDefined() && method.Name != "GetInstance")) continue; instanceGetter = method; @@ -186,7 +186,7 @@ public abstract class ModdedOptionMemberAttribute(string? memberName, Type? hold { foreach (var prop in type.GetProperties(getterFlags)) { - if (prop.GetCustomAttribute() == null && prop.Name != "Instance") + if (prop.IsDefined() && prop.Name != "Instance") continue; var getMethod = prop.GetGetMethod(canSearchPrivates); @@ -213,7 +213,7 @@ public abstract class ModdedOptionMemberAttribute(string? memberName, Type? hold return null; } } - else if (type.GetCustomAttribute() != null) + else if (type.IsDefined()) { flags |= BindingFlags.NonPublic; } diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index c814d957..6bc448bd 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -117,7 +117,7 @@ public sealed class MiraPluginManager { foreach (var type in assembly.GetTypes()) { - if ((isMira && type.IsAbstract) || type.GetCustomAttribute() != null) + if ((isMira && type.IsAbstract) || type.IsDefined()) continue; RegisterEvents(type); @@ -226,7 +226,7 @@ public sealed class MiraPluginManager foreach (var property in type.GetProperties()) { - if (property.IsDefined(false)) + if (property.IsDefined()) continue; var getter = property.GetMethod; @@ -426,7 +426,7 @@ public sealed class MiraPluginManager continue; } - if (property.GetCustomAttribute() != null && + if (property.IsDefined() && property.PropertyType.IsAssignableTo(typeof(LocalSettingsButton))) { var button = property.GetValue(tabInstance) as LocalSettingsButton; @@ -453,15 +453,13 @@ public sealed class MiraPluginManager } var attribute = property.GetCustomAttribute(); - if (attribute == null) + if (attribute != null) { - continue; + attribute.CreateSetting(type, configEntry); } - - attribute.CreateSetting(type, configEntry); } - foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(ConfigEntryBase)) && f.GetCustomAttribute() != null)) + foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(ConfigEntryBase)) && f.IsDefined())) { Error($"{field.Name} is a field, not a property. Use properties for local settings."); } @@ -480,7 +478,7 @@ public sealed class MiraPluginManager { try { - if (type.GetCustomAttribute() == null) + if (type.IsDefined()) { return; }