public void Dispose() { if (_observer != null) { _observers.TryRemove(_observer.GetHashCode(), out var observer); } }
public IDisposable Subscribe(IObserver <EventArgs> subscriber) { var subscription = new Subscription(this, subscriber); m_subscribers.Add(subscription); Console.WriteLine("Subscribe: {0}", subscriber.GetHashCode()); return(subscription); }
//add another observer to the subscriber list public IDisposable Subscribe(IObserver <int> observer) { if (subscriberList.Contains(observer)) { throw new ArgumentException("The observer is already subscribed to this observable"); } Console.WriteLine("Subscribing for {0}", observer.GetHashCode()); subscriberList.Add(observer); return(null); }
public void RemoveObserver(IObserver observable) { var hash = observable.GetHashCode(); var index = _observers.FindIndex(x => x.GetHashCode().Equals(hash)); if (index != -1) { _observers.RemoveAt(index); } else { Debug.LogError(observable.GetType().FullName + " already unsubscribed."); } }
public void AddObserver(IObserver observable) { var hash = observable.GetHashCode(); var index = _observers.FindIndex(x => x.GetHashCode().Equals(hash)); if (index == -1) { _observers.Add(observable); } else { Debug.LogError(observable.GetType().FullName + " subscribe duplication."); } }
//add another observer to the subscriber list public IDisposable Subscribe(IObserver <int> observer) { if (observerList.Contains(observer)) { throw new ArgumentException("The observer is already subscribed to this observable"); } Console.WriteLine("Subscribing for {0}", observer.GetHashCode()); observerList.Add(observer); //creates a new subscription for the given observer var subscription = new Subscription <int>(observer); //handle to the subscription lifecycle end event subscription.OnCompleted += OnObserverLifecycleEnd; return(subscription); }
public ObSubscription(IObserver <T> observer, Action <ObSubscription> onDispose) { Id = observer.GetHashCode(); Observer = observer; _onDispose = onDispose; }
public void removeObserver(IObserver ob) { observers.Remove(ob.GetHashCode().ToString()); }
public void registerObserver(IObserver ob) { observers.Add(ob.GetHashCode().ToString(), ob); }
/// <summary>Получить хэш-код связи</summary> /// <param name="Observers">Коллекция наблюдателей</param> /// <param name="Observer">Добавляемый наблюдатель</param> /// <returns>Хэш-код связи</returns> private static int GetHash([NotNull] ICollection <IObserver <T> > Observers, [NotNull] IObserver <T> Observer) { unchecked { return(Observer.GetHashCode() * 397 ^ Observers.GetHashCode()); } }
public ObserverSubscription(IObserver <T> observer, Action <ObserverSubscription> disposer) { Id = observer.GetHashCode(); Observer = observer; this.disposer = disposer; }
public void Unsubscribe(IObserver <EventArgs> subscriber) { Console.WriteLine("Unsubscribe: {0}", subscriber.GetHashCode()); m_subscribers.RemoveAll(s => s.Subscriber == subscriber); }