Exemplo n.º 1
0
        public IDisposable Subscribe(IUpdatableCollection collection)
        {
            WeakReference <IUpdatableCollection> collectionReference = updateSubscriptions.AddAndReturnReference(collection);

            return(new DelegateDisposable(delegate()
            {
                updateSubscriptions.Remove(collectionReference);
            }));
        }
        public IDisposable Subscribe(IUpdatableCollection collection)
        {
            // Store the IUpdatableCollection in a WeakReferenceList

            WeakReference <IUpdatableCollection> collectionReference = updateSubscriptions.AddAndReturnReference(collection);

            // Subscribe to the source if there is not currently a subscription in place

            if (sourceUpdateDisposable == null)
            {
                sourceUpdateDisposable = source.Subscribe(this);
            }

            // Return an IDisposable to remove the subscription

            return(new DelegateDisposable(delegate()
            {
                updateSubscriptions.Remove(collectionReference);
                UnsubscribeFromSourceIfNoSubscribers();
            }));
        }