mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
Added overloads, backwards compatibility stand tall
This commit is contained in:
1 parent
eca00dbfcd
commit
14cd9eedf4
2 files changed
+79
-4
No files matched your search
@@ -122,7 +122,7 @@ public static class MiraEventManager
|
||||
/// <param name="priority">The priority of the event handler. Lower values are called first.</param>
|
||||
/// <param name="invokeOnSubtype">Whether the event handler should also be triggered by subclasses of the <see cref="MiraEvent"/> type of the handler.</param>
|
||||
/// <returns>A <see cref="MiraEventHandle"/> to use when unregistering the event.</returns>
|
||||
public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, int priority = 0, bool invokeOnSubtype = true)
|
||||
public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, int priority, bool invokeOnSubtype)
|
||||
{
|
||||
if (!type.IsAssignableTo(typeof(MiraEvent)))
|
||||
{
|
||||
@@ -133,6 +133,24 @@ public static class MiraEventManager
|
||||
return RegisterEventHandler(type, @delegate, priority, invokeOnSubtype);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler(Type, MethodInfo, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, int priority)
|
||||
{
|
||||
return RegisterEventHandler(type, methodInfo, priority, true);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler(Type, MethodInfo, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, bool invokeOnSubtype)
|
||||
{
|
||||
return RegisterEventHandler(type, methodInfo, 0, invokeOnSubtype);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler(Type, MethodInfo, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
return RegisterEventHandler(type, methodInfo, 0, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a <see cref="MiraEvent"/> handler.
|
||||
/// </summary>
|
||||
@@ -140,11 +158,29 @@ public static class MiraEventManager
|
||||
/// <param name="priority">The priority of the event handler. Lower values are called first.</param>
|
||||
/// <param name="invokeOnSubtype">Whether the event handler should also be triggered by subclasses of the <see cref="MiraEvent"/> type of the handler.</param>
|
||||
/// <returns>A <see cref="MiraEventHandle"/> to use when unregistering the event.</returns>
|
||||
public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, int priority = 0, bool invokeOnSubtype = true)
|
||||
public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, int priority, bool invokeOnSubtype)
|
||||
{
|
||||
return RegisterEventHandler(methodInfo.GetParameters()[0].ParameterType, methodInfo, priority, invokeOnSubtype);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler(MethodInfo, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, int priority)
|
||||
{
|
||||
return RegisterEventHandler(methodInfo, priority, true);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler(MethodInfo, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, bool invokeOnSubtype)
|
||||
{
|
||||
return RegisterEventHandler(methodInfo, 0, invokeOnSubtype);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler(MethodInfo, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo)
|
||||
{
|
||||
return RegisterEventHandler(methodInfo, 0, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a <typeparamref name="T"/> handler.
|
||||
/// </summary>
|
||||
@@ -153,12 +189,33 @@ public static class MiraEventManager
|
||||
/// <param name="invokeOnSubtype">Whether the event handler should also be triggered by subclasses of the <see cref="MiraEvent"/> type of the handler.</param>
|
||||
/// <typeparam name="T">Type of <see cref="MiraEvent"/> event.</typeparam>
|
||||
/// <returns>A <see cref="MiraEventHandle"/> to use when unregistering the event.</returns>
|
||||
public static MiraEventHandle RegisterEventHandler<T>(Action<T> handler, int priority = 0, bool invokeOnSubtype = true)
|
||||
public static MiraEventHandle RegisterEventHandler<T>(Action<T> handler, int priority, bool invokeOnSubtype)
|
||||
where T : MiraEvent
|
||||
{
|
||||
return RegisterEventHandler(typeof(T), handler, priority, invokeOnSubtype);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler{T}(Action{T}, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler<T>(Action<T> handler, int priority)
|
||||
where T : MiraEvent
|
||||
{
|
||||
return RegisterEventHandler(handler, priority, true);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler{T}(Action{T}, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler<T>(Action<T> handler, bool invokeOnSubtype)
|
||||
where T : MiraEvent
|
||||
{
|
||||
return RegisterEventHandler(handler, 0, invokeOnSubtype);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventHandler{T}(Action{T}, int, bool)"/>
|
||||
public static MiraEventHandle RegisterEventHandler<T>(Action<T> handler)
|
||||
where T : MiraEvent
|
||||
{
|
||||
return RegisterEventHandler(handler, 0, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a <see cref="MiraEvent"/> handler.
|
||||
/// </summary>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Events;
|
||||
/// <param name="priority">The priority of the event. Lower values are called first.</param>
|
||||
/// <param name="invokeOnSubtype">Whether the event handler should also be triggered by subclasses of the <see cref="MiraEvent"/> type of the handler.</param>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class RegisterEventAttribute(int priority = 0, bool invokeOnSubtype = true) : Attribute
|
||||
public class RegisterEventAttribute(int priority, bool invokeOnSubtype) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the priority of the event. Lower values are called first.
|
||||
@@ -20,4 +20,22 @@ public class RegisterEventAttribute(int priority = 0, bool invokeOnSubtype = tru
|
||||
/// triggered by subclasses of the <see cref="MiraEvent"/> type of the handler.
|
||||
/// </summary>
|
||||
public bool InvokeOnSubtype { get; } = invokeOnSubtype;
|
||||
|
||||
/// <inheritdoc cref="RegisterEventAttribute"/>
|
||||
public RegisterEventAttribute(int priority)
|
||||
: this(priority, true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventAttribute"/>
|
||||
public RegisterEventAttribute(bool invokeOnSubtype)
|
||||
: this(0, invokeOnSubtype)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RegisterEventAttribute"/>
|
||||
public RegisterEventAttribute()
|
||||
: this(0, true)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user