public CollectionMonitor(IList <T> input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            INotifyCollectionChanged inputAsINotifyCollectionChanged = input as INotifyCollectionChanged;

            if (inputAsINotifyCollectionChanged == null)
            {
                throw new ArgumentException("Collections must implement INotifyCollectionChanged.");
            }

            _input = input;

            _Properties = new List <PropertyNotifier <T> >();
            Properties  = new ReadOnlyCollection <PropertyNotifier <T> >(_Properties);

            ReferenceCountTracker = new ReferenceCountTracker <T>();

            WeakNotifyCollectionChangedEventHandler.Register(
                inputAsINotifyCollectionChanged,
                this,
                (me, sender, args) => me.OnCollectionChanged(args));

            // Add Items to Reference Counter
            foreach (var item in input)
            {
                ReferenceCountTracker.Add(item);
            }
        }
        public NotifyCollectionChangedMonitor(PropertyAccessTree propertyAccessTree, IList <T> input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            INotifyCollectionChanged inputAsINotifyCollectionChanged = input as INotifyCollectionChanged;

            if (inputAsINotifyCollectionChanged == null)
            {
                throw new ArgumentException("Collections must implement INotifyCollectionChanged to work with CLINQ");
            }

            _input = input;

            this.PropertyAccessTree = propertyAccessTree;

            this.ReferenceCountTracker = new ReferenceCountTracker <T>();

            SetupPropertyChangeSubscription();

            SubscribeToItems(_input);

            WeakNotifyCollectionChangedEventHandler.Register(
                inputAsINotifyCollectionChanged,
                this,
                (me, sender, args) => me.OnCollectionChanged(sender, args));
        }
Пример #3
0
        /// <summary>
        /// Creates a weak delegate from an Action delegate.
        /// </summary>
        public static NotifyCollectionChangedEventHandler From(NotifyCollectionChangedEventHandler strongHandler)
        {
            AssertIsWeakDelegate(strongHandler);

            var wrapper = new WeakNotifyCollectionChangedEventHandler(strongHandler);

            return(wrapper.Execute);
        }
        private IndexingSkipList <IList <TResult> > .Node RecordItem(IndexingSkipList <IList <TResult> > .Node nodeBefore, TSource item, IList <TResult> collection)
        {
            int count   = GetCount(collection);
            var newNode = _collectionIndex.AddAfter(nodeBefore, count, collection);

            RecordNodeForItemInLookupTables(item, collection, newNode);

            if (collection != null && !_weakEventHandlers.ContainsKey(collection))
            {
                WeakEventHandler weakEventHandler = WeakNotifyCollectionChangedEventHandler.Register(
                    (INotifyCollectionChanged)collection,
                    this,
                    (me, sender, args) => me.OnSubCollectionChanged(sender, args));

                _weakEventHandlers.Add(collection, weakEventHandler);
            }

            return(newNode);
        }