public ObservableCollectionProxy(IEnumerable <T> inner)
        {
            if (inner == null)
            {
                throw new ArgumentNullException("inner");
            }

            this.inner    = inner;
            this.listener = new CollectionChangeListener <T>(this);
        }
예제 #2
0
            private void ResetChildListener(string propertyName)
            {
                if (m_childListeners.ContainsKey(propertyName))
                {
                    // Unsubscribe if existing
                    if (m_childListeners[propertyName] != null)
                    {
                        m_childListeners[propertyName].PropertyChanged -= child_PropertyChanged;

                        // Should unsubscribe all events
                        m_childListeners[propertyName].Unsubscribe();
                        m_childListeners[propertyName] = null;
                    }

                    var property = m_type.GetProperty(propertyName);
                    if (property == null)
                    {
                        throw new InvalidOperationException($"Was unable to get '{propertyName}' property information from Type '{m_type.Name}'");
                    }

                    object newValue = property.GetValue(m_value, null);

                    // Only recreate if there is a new value
                    if (newValue != null)
                    {
                        if (newValue is INotifyCollectionChanged)
                        {
                            m_childListeners[propertyName] =
                                new CollectionChangeListener(newValue as INotifyCollectionChanged, propertyName);
                        }
                        else if (newValue is INotifyPropertyChanged)
                        {
                            m_childListeners[propertyName] =
                                new ChildChangeListener(newValue as INotifyPropertyChanged, propertyName);
                        }

                        if (m_childListeners[propertyName] != null)
                        {
                            m_childListeners[propertyName].PropertyChanged += child_PropertyChanged;
                        }
                    }
                }
            }
예제 #3
0
        void SequencesCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action != NotifyCollectionChangedAction.Reset)
            {
                var notification = CollectionChangedNotificationResult <T> .Create(this);

                var removed = notification.RemovedItems;
                var added   = notification.AddedItems;

                if (e.OldItems != null)
                {
                    foreach (IEnumerable <T> sequence in e.OldItems)
                    {
                        removed.AddRange(sequence);
                        INotifyCollectionChanged notifier = sequence as INotifyCollectionChanged;
                        if (notifier != null)
                        {
                            var listener = changeListener[sequence];
                            listener.Unsubscribe();
                            changeListener.Remove(sequence);
                        }
                    }
                }
                if (e.NewItems != null)
                {
                    foreach (IEnumerable <T> sequence in e.NewItems)
                    {
                        added.AddRange(sequence);
                        INotifyCollectionChanged notifier = sequence as INotifyCollectionChanged;
                        if (notifier != null)
                        {
                            var listener = new CollectionChangeListener <T>(this);
                            listener.Subscribe(notifier);
                            changeListener.Add(sequence, listener);
                        }
                    }
                }

                ExecutionMetaData.Results.Add(notification);
            }
            ExecutionEngine.Current.InvalidateNode(this);
        }
            private void ResetChildListener(INotifyPropertyChanged item)
            {
                if (item == null)
                {
                    throw new ArgumentNullException(nameof(item));
                }

                RemoveItem(item);

                ChangeListener listener;

                // Add new
                if (item is INotifyCollectionChanged)
                {
                    listener = new CollectionChangeListener((INotifyCollectionChanged)item, PropertyName);
                }
                else
                {
                    listener = new ChildChangeListener(item);
                }

                listener.PropertyChanged += listener_PropertyChanged;
                m_collectionListeners.Add(item, listener);
            }