private void ExecuteOnCollectionChanged(IEnumerable <T> collection, ProcessRangeAction state)
        {
            if (BeforeCollectionChanged == null)
            {
                return;
            }

            BeforeCollectionChanged(collection, state);
        }
        protected virtual void ProcessRange(IEnumerable <T> collection, ProcessRangeAction action)
        {
            lock (_lockObj)
            {
                try
                {
                    if (collection == null)
                    {
                        throw new ArgumentNullException("collection");
                    }

                    var items = collection as IList <T> ?? collection.ToList();
                    if (!items.Any())
                    {
                        return;
                    }

                    CheckReentrancy();

                    if (action == ProcessRangeAction.Replace)
                    {
                        Items.Clear();
                    }

                    foreach (var item in items)
                    {
                        if (action == ProcessRangeAction.Remove)
                        {
                            Items.Remove(item);
                        }
                        else
                        {
                            Items.Add(item);
                        }
                    }

                    OnPropertyChanged(new PropertyChangedEventArgs(CountString));
                    OnPropertyChanged(new PropertyChangedEventArgs(IndexerName));
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                }
                catch { }
            }
        }
        protected virtual void ProcessRange(IEnumerable <T> collection, ProcessRangeAction action)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            var items = collection as IList <T> ?? collection.ToList();

            if (!items.Any())
            {
                return;
            }

            ExecuteOnCollectionChanged(collection, action);

            this.CheckReentrancy();

            if (action == ProcessRangeAction.Replace)
            {
                this.Items.Clear();
            }
            foreach (var item in items)
            {
                if (action == ProcessRangeAction.Remove)
                {
                    this.Items.Remove(item);
                }
                else
                {
                    this.Items.Add(item);
                }
            }

            //if (action == ProcessRangeAction.Remove) { }
            //else
            //	(this.Items as List<T>).AddRange(items);

            this.OnPropertyChanged(new PropertyChangedEventArgs(CountString));
            this.OnPropertyChanged(new PropertyChangedEventArgs(IndexerName));
            this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
예제 #4
0
        protected virtual void ProcessRange(IEnumerable <T> collection, ProcessRangeAction action)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            var items = collection as IList <T> ?? collection.ToList();

            if (!items.Any())
            {
                return;
            }

            CheckReentrancy();

            m_IsInProcessRange = true;

            if (action == ProcessRangeAction.Replace)
            {
                Items.Clear();
            }

            foreach (var item in items)
            {
                if (action == ProcessRangeAction.Remove)
                {
                    Items.Remove(item);
                }
                else
                {
                    Items.Add(item);
                }
            }
            m_IsInProcessRange = false;

            OnPropertyChanged(new PropertyChangedEventArgs(COUNT_STRING));
            OnPropertyChanged(new PropertyChangedEventArgs(INDEXER_NAME));
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }