mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
Allowed correct generic tracking
This commit is contained in:
1 parent
8410d61ac5
commit
8619fe8675
1 file changed
+24
-8
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user