예제 #1
0
        // *** Constructors ***

        public VirtualizingDataList(IDataListSource <T> dataListSource)
        {
            // Validate the parameters

            if (dataListSource == null)
            {
                throw new ArgumentNullException("dataListSource");
            }

            // Set the fields and subscribe for collection updates

            this.dataListSource = dataListSource;
            dataListSource.Subscribe(this);
        }
        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();
            }));
        }