From eca00dbfcd49a300cba3c6bfe95e9fe0eeac0c25 Mon Sep 17 00:00:00 2001
From: David Higueros <111460331+TheDavSmasher@users.noreply.github.com>
Date: Fri, 6 Nov 2026 14:54:10 -0700
Subject: [PATCH] Moved method to extensions
---
MiraAPI/Events/MiraEventManager.cs | 23 +----------------------
MiraAPI/Utilities/Extensions.cs | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/MiraAPI/Events/MiraEventManager.cs b/MiraAPI/Events/MiraEventManager.cs
index e5d296e1..b5bbfad9 100644
--- a/MiraAPI/Events/MiraEventManager.cs
+++ b/MiraAPI/Events/MiraEventManager.cs
@@ -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);
- }
-
///
/// Register a handler.
///
diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs
index d3a0fbae..29f8b623 100644
--- a/MiraAPI/Utilities/Extensions.cs
+++ b/MiraAPI/Utilities/Extensions.cs
@@ -601,6 +601,35 @@ public static class Extensions
return type is { IsClass: true, IsAbstract: true, IsSealed: true };
}
+ ///
+ /// Checks if is a subclass of , including
+ /// account for generics, or given generic type definitions.
+ ///
+ /// The type to check.
+ /// The type to compare against.
+ /// if is a sublass of , otherwise.
+ 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);
+ }
+
///
/// Gets a darkened version of a .
///