From f7b35e64ec8a7561159d8ba26efa92a76d8804df Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 5 Jun 2020 12:26:25 -0400 Subject: [PATCH] feat: Added extension method for getting the EventArgs type for a given EventInfo --- .../Extensions/ReflectionExtensions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs index 4e30516..e19698c 100644 --- a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs +++ b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs @@ -128,5 +128,22 @@ namespace ICD.Common.Utils.Extensions .Distinct(); } #endif + + /// + /// Gets the EventArgs Type for the given event. + /// + /// + /// + 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(); + } } }