diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs
index 1260bb6..534ca34 100644
--- a/ICD.Common.Utils/ReflectionUtils.cs
+++ b/ICD.Common.Utils/ReflectionUtils.cs
@@ -414,5 +414,43 @@ namespace ICD.Common.Utils
throw new InvalidCastException(message, e);
}
}
+
+ ///
+ /// 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)
+ {
+ if (eventInfo == null)
+ throw new ArgumentNullException("eventInfo");
+
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+
+ Delegate output = CreateDelegate(eventInfo.EventHandlerType, handler, callback);
+ 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);
+ }
}
}