Moved method to extensions

This commit is contained in:
David Higueros committed 2026-11-06 14:54:10 -07:00
1 parent 06b7099ba5
commit eca00dbfcd
2 files changed
+30 -22

No files matched your search

+1 -22
View File
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using MiraAPI.PluginLoading;
using MiraAPI.Utilities;
namespace MiraAPI.Events;
@@ -113,28 +114,6 @@ public static class MiraEventManager
trackedEvents.Add(trackedAs);
}
private static bool IsSubclassOfWithGeneric(this Type? type, Type super)
{
if (type == null || type == typeof(MiraEvent))
{
return false;
}
if (type == super)
{
return true;
}
if (super.IsGenericTypeDefinition &&
type.IsGenericType &&
type.GetGenericTypeDefinition() == super)
{
return true;
}
return type.BaseType.IsSubclassOfWithGeneric(super);
}
/// <summary>
/// Register a <see cref="MiraEvent"/> handler.
/// </summary>
+29
View File
@@ -601,6 +601,35 @@ public static class Extensions
return type is { IsClass: true, IsAbstract: true, IsSealed: true };
}
/// <summary>
/// Checks if <paramref name="type"/> is a subclass of <paramref name="super"/>, including
/// account for generics, or given generic type definitions.
/// </summary>
/// <param name="type">The type to check.</param>
/// <param name="super">The type to compare against.</param>
/// <returns><see langword="true"/> if <paramref name="type"/> is a sublass of <paramref name="type"/>, <see langword="false"/> otherwise.</returns>
public static bool IsSubclassOfWithGeneric(this Type? type, Type super)
{
if (type == null || type == typeof(object))
{
return false;
}
if (type == super)
{
return true;
}
if (super.IsGenericTypeDefinition &&
type.IsGenericType &&
type.GetGenericTypeDefinition() == super)
{
return true;
}
return type.BaseType.IsSubclassOfWithGeneric(super);
}
/// <summary>
/// Gets a darkened version of a <see cref="Color32"/>.
/// </summary>