/// <summary> /// Initializes a new instance of the <see cref="WeakEventSubscription{T1, T2}" /> class. /// </summary> /// <param name="target">The target.</param> /// <param name="eventHandler">The event handler.</param> /// <param name="subscribeAction">The action to subscribe the event handler.</param> /// <param name="unsubscribeAction">The action to unsubscribe the event handler.</param> public WeakEventSubscription(object target, TypedEventHandler <T1, T2> eventHandler, Action <TypedEventHandler <T1, T2> > subscribeAction, Action <TypedEventHandler <T1, T2> > unsubscribeAction) { _unsubscribeAction = unsubscribeAction; Method = eventHandler.GetMethodInfo(); EventHandlerReference = new WeakReference(eventHandler.Target); Reference = new WeakReference(target); subscribeAction(OnEvent); }
public WeakTypedEventHandler(TypedEventHandler <TSender, TResult> callback) { // Since we originally weak referenced the event handler, the event handler will obviously be disposed unless the calling // subscriber holds a reference to it. // We'll hold a weak reference to the subscriber target _targetReference = new WeakReference(callback.Target); // And also obtain the actual method info _methodInfo = callback.GetMethodInfo(); }