コード例 #1
0
 /// <summary>
 /// Remove an event handler from the event handler invocation list.
 /// </summary>
 /// <param name="handler">The hander to remove</param>
 public void Remove(E handler)
 {
     WeakEventRegistration.Unregister(
         eh =>
     {
         lock (_eventHandlersLock)
         {
             _eventHandlers = (E)(Delegate.Remove((Delegate)(_eventHandlers as object), (Delegate)(eh as object)) as object);
             return(_eventHandlers);
         }
     },
         handler);
 }
コード例 #2
0
 /// <summary>
 /// Add an event handler to the invocation list of event handlers. If the event handler is for an instance method will create
 /// a weak reference to the target instance, so its lifetime is not dependent on the lifetime of the event source
 /// </summary>
 /// <param name="handler">The handler to add</param>
 public void Add(E handler)
 {
     WeakEventRegistration.Register(
         eh =>
     {
         lock (_eventHandlersLock)
         {
             _eventHandlers = (E)(Delegate.Combine((Delegate)(_eventHandlers as object), (Delegate)(eh as object)) as object);
         }
     },
         handler,
         _weakHandlerGetter,
         eh =>
     {
         lock (_eventHandlersLock)
         {
             _eventHandlers = (E)(Delegate.Remove((Delegate)(_eventHandlers as object), (Delegate)(eh as object)) as object);
         }
     }
         );
 }