mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 03:57:32 +00:00
feat: Added extension method for getting the EventArgs type for a given EventInfo
This commit is contained in:
parent
bfab3c77b0
commit
f7b35e64ec
1 changed files with 17 additions and 0 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue