mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
feat: Added extension method for getting the EventArgs type for a given EventInfo
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user