예제 #1
0
        private void ResetChildListener(INotifyPropertyChanged item)
        {
            Requires.NotNull(item, "item");

            RemoveItem(item);

            ChangeListener listener = null;

            if (item is INotifyCollectionChanged)
                listener = new CollectionChangeListener(item as INotifyCollectionChanged, PropertyName);
            else
                listener = new ChildChangeListener(item);

            listener.PropertyChanged += ListenerPropertyChanged;
            m_collectionListeners.Add(item, listener);
        }
예제 #2
0
        /// <summary>
        /// Resets known (must exist in children collection) child event handlers
        /// </summary>
        /// <param name="propertyName">Name of known child property</param>
        private void ResetChildListener(string propertyName)
        {
            if (m_childListeners.ContainsKey(propertyName))
            {
                // Unsubscribe if existing
                if (m_childListeners[propertyName] != null)
                {
                    m_childListeners[propertyName].PropertyChanged -= ChildPropertyChanged;

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

                var property = m_type.GetProperty(propertyName);
                if (property == null)
                {
                    throw new InvalidOperationException(string.Format("Was unable to get '{0}' property information from Type '{1}'", propertyName, 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 += ChildPropertyChanged;
                    }
                }
            }
        }
        /// <summary>
        /// Resets known (must exist in children collection) child event handlers
        /// </summary>
        /// <param name="propertyName">Name of known child property</param>
        private void ResetChildListener(string propertyName)
        {
            if (m_childListeners.ContainsKey(propertyName))
            {
                // Unsubscribe if existing
                if (m_childListeners[propertyName] != null)
                {
                    m_childListeners[propertyName].PropertyChanged -= ChildPropertyChanged;

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

                var property = m_type.GetProperty(propertyName);
                if (property == null)
                    throw new InvalidOperationException(string.Format("Was unable to get '{0}' property information from Type '{1}'", propertyName, 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 += ChildPropertyChanged;
                }
            }
        }