diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index d21b9c9..534ca34 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -418,10 +418,10 @@ namespace ICD.Common.Utils /// /// Subscribes to the event on the given instance using the handler and callback method. /// - /// - /// - /// - /// + /// The instance with the event. Null for static types. + /// The EventInfo for the event. + /// The instance with the callback MethodInfo. Null for static types. + /// The MethodInfo for the callback method. /// public static Delegate SubscribeEvent(object instance, EventInfo eventInfo, object handler, MethodInfo callback) { @@ -435,5 +435,22 @@ namespace ICD.Common.Utils eventInfo.AddEventHandler(instance, output); return output; } + + /// + /// Unsubscribes from the event on the given instance. + /// + /// The instance with the event. Null for static types. + /// The EventInfo for the event. + /// The Delegate to be removed from the event. + public static void UnsubscribeEvent(object instance, EventInfo eventInfo, Delegate callback) + { + if (eventInfo == null) + throw new ArgumentNullException("eventInfo"); + + if (callback == null) + throw new ArgumentNullException("callback"); + + eventInfo.RemoveEventHandler(instance, callback); + } } }