feat: Added extension method for getting the EventArgs type for a given EventInfo

This commit is contained in:
Chris Cameron
2020-06-05 12:26:25 -04:00
parent bfab3c77b0
commit f7b35e64ec

View File

@@ -128,5 +128,22 @@ namespace ICD.Common.Utils.Extensions
.Distinct();
}
#endif
/// <summary>
/// Gets the EventArgs Type for the given event.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static Type GetEventArgsType([NotNull] this EventInfo extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
Type eventHandlerType = extends.EventHandlerType;
return eventHandlerType == typeof(EventHandler)
? typeof(EventArgs)
: eventHandlerType.GetInnerGenericTypes(typeof(EventHandler<>))
.First();
}
}
}