Merge branch 'dev' into color-ids

This commit is contained in:
Az committed 2026-11-03 09:26:52 -05:00
commit e62d3c4b05
3 files changed
+27 -13

No files matched your search

@@ -166,7 +166,7 @@ public abstract class ModdedOptionMemberAttribute(string? memberName, Type? hold
{
flags |= BindingFlags.Instance;
var canSearchPrivates = type.GetCustomAttribute<SearchPrivateAttribute>() != null;
var canSearchPrivates = type.IsDefined<SearchPrivateAttribute>();
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<InstanceGetterAttribute>() == null && method.Name != "GetInstance"))
if (method.GetParameters().Length > 0 || (method.IsDefined<InstanceGetterAttribute>() && 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<InstanceGetterAttribute>() == null && prop.Name != "Instance")
if (prop.IsDefined<InstanceGetterAttribute>() && 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<SearchPrivateAttribute>() != null)
else if (type.IsDefined<SearchPrivateAttribute>())
{
flags |= BindingFlags.NonPublic;
}
+7 -9
View File
@@ -117,7 +117,7 @@ public sealed class MiraPluginManager
{
foreach (var type in assembly.GetTypes())
{
if ((isMira && type.IsAbstract) || type.GetCustomAttribute<MiraIgnoreAttribute>() != null)
if ((isMira && type.IsAbstract) || type.IsDefined<MiraIgnoreAttribute>())
continue;
RegisterEvents(type);
@@ -223,7 +223,7 @@ public sealed class MiraPluginManager
foreach (var property in type.GetProperties())
{
if (property.GetCustomAttribute<MiraIgnoreAttribute>() != null)
if (property.IsDefined<MiraIgnoreAttribute>())
continue;
if (property.GetMethod?.IsStatic == true)
@@ -416,7 +416,7 @@ public sealed class MiraPluginManager
continue;
}
if (property.GetCustomAttribute<LocalSettingsButtonAttribute>() != null &&
if (property.IsDefined<LocalSettingsButtonAttribute>() &&
property.PropertyType.IsAssignableTo(typeof(LocalSettingsButton)))
{
var button = property.GetValue(tabInstance) as LocalSettingsButton;
@@ -443,15 +443,13 @@ public sealed class MiraPluginManager
}
var attribute = property.GetCustomAttribute<LocalSettingAttribute>();
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<LocalSettingAttribute>() != null))
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(ConfigEntryBase)) && f.IsDefined<LocalSettingAttribute>()))
{
Error($"{field.Name} is a field, not a property. Use properties for local settings.");
}
@@ -470,7 +468,7 @@ public sealed class MiraPluginManager
{
try
{
if (type.GetCustomAttribute<RegisterCustomKeybindsAttribute>() == null)
if (type.IsDefined<RegisterCustomKeybindsAttribute>())
{
return;
}
+16
View File
@@ -842,4 +842,20 @@ public static class Extensions
var comp = go.GetComponent<T>();
return comp ? comp : go.AddComponent<T>();
}
/// <inheritdoc cref="Attribute.IsDefined(MemberInfo, Type, bool)"/>
/// <typeparam name="T">The type of the attribute.</typeparam>
/// <returns>true if a custom attribute of type <typeparamref name="T"/> is applied to element; otherwise, false.</returns>
public static bool IsDefined<T>(this MemberInfo element, bool inherit)
where T : Attribute
{
return Attribute.IsDefined(element, typeof(T), inherit);
}
/// <inheritdoc cref="IsDefined{T}(MemberInfo, bool)"/>
public static bool IsDefined<T>(this MemberInfo element)
where T : Attribute
{
return Attribute.IsDefined(element, typeof(T));
}
}