private void RemoveHandlerPrivate <TMessage>(ISubscriberTo <TMessage> subscriberTo) where TMessage : class { if (ContainsKey(typeof(TMessage))) { this[typeof(TMessage)].RemoveAll(wr => wr.Target.As <ISubscriberTo <TMessage> >() == subscriberTo); } InvalidateHandlers(); }
public void RemoveHandler <TMessage>(ISubscriberTo <TMessage> subscriberTo) where TMessage : class { ArgumentMust.NotBeNull(() => subscriberTo); lock (_thisLock) { RemoveHandlerPrivate(subscriberTo); } }
private void AddHandlerPrivate <TMessage>(ISubscriberTo <TMessage> subscriberTo) where TMessage : class { if (ContainsKey(typeof(TMessage))) { if (this[typeof(TMessage)].All(wr => wr.Target.As <ISubscriberTo <TMessage> >() != subscriberTo)) { this[typeof(TMessage)].Add(new WeakReference(subscriberTo)); } } else { Add(typeof(TMessage), new Handlers(new WeakReference(subscriberTo))); } InvalidateHandlers(); }
public void UnsubscribeFrom <TMessage>(ISubscriberTo <TMessage> subscriberTo) where TMessage : class { ArgumentMust.NotBeNull(() => subscriberTo); _handlers.RemoveHandler(subscriberTo); }
public void SubscribeTo <TMessage>(ISubscriberTo <TMessage> subscriberTo) where TMessage : class { ArgumentMust.NotBeNull(() => subscriberTo); _handlers.AddHandler(subscriberTo); }