Allowed correct generic tracking

This commit is contained in:
David Higueros committed 2026-11-03 15:38:45 -07:00
1 parent 8410d61ac5
commit 8619fe8675
1 file changed
+24 -8
+24 -8
View File
@@ -106,15 +106,9 @@ public static class MiraEventManager
trackedEvents.Add(eventType);
}
foreach (var superType in StoredEventTypes.Where(x => x.IsAssignableFrom(eventType)))
{
if (!eventType.IsAbstract)
{
TrackedEventTypes[eventType].Add(superType);
}
}
TrackedEventTypes[eventType].AddRange(StoredEventTypes.Where(x => IsSubclassOf(eventType, x)));
foreach (var subType in StoredEventTypes.Where(x => x.IsAssignableTo(eventType)))
foreach (var subType in StoredEventTypes.Where(x => IsSubclassOf(x, eventType)))
{
if (!subType.IsAbstract)
{
@@ -133,6 +127,28 @@ public static class MiraEventManager
return true;
}
private static bool IsSubclassOf(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 IsSubclassOf(type.BaseType, super);
}
/// <summary>
/// Register a <see cref="MiraEvent"/> handler.
/// </summary>