Esempio n. 1
0
        private void ResetChildListener(INotifyPropertyChanged item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            RemoveItem(item);

            ChangeListener listener = null;

            // Add new
            if (item is INotifyCollectionChanged)
                listener = new CollectionChangeListener(item as INotifyCollectionChanged, _propertyName);
            else
                listener = new ChildChangeListener(item as INotifyPropertyChanged);

            listener.PropertyChanged += new PropertyChangedEventHandler(listener_PropertyChanged);
            _collectionListeners.Add(item, listener);
        }
            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;
                        }
                    }
                }
            }
            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);
            }