IsUsefulForObject() public static method

Determines whether creating a ChangeNotificationWrapper is useful for the specified object. An object is considered usable when it implements either INotifyPropertyChanged or INotifyCollectionChanged.
public static IsUsefulForObject ( object obj ) : bool
obj object The object to check.
return bool
Exemplo n.º 1
0
        /// <summary>
        /// Handles the object events subscription. This means that the old value will be removed from the event subscriptions, and
        /// the new value will be subscribed to.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="propertyValue">The property value.</param>
        private void HandleObjectEventsSubscription(string propertyName, object propertyValue)
        {
            if (DisableEventSubscriptionsOfChildValues)
            {
                return;
            }

            lock (_propertyValuesLock)
            {
                if (_propertyValueChangeNotificationWrappers.ContainsKey(propertyName))
                {
                    var oldWrapper = _propertyValueChangeNotificationWrappers[propertyName];
                    if (oldWrapper != null)
                    {
                        oldWrapper.PropertyChanged               -= OnPropertyObjectPropertyChanged;
                        oldWrapper.CollectionChanged             -= OnPropertyObjectCollectionChanged;
                        oldWrapper.CollectionItemPropertyChanged -= OnPropertyObjectCollectionItemPropertyChanged;
                        oldWrapper.UnsubscribeFromAllEvents();
                    }
                }

                if (!ChangeNotificationWrapper.IsUsefulForObject(propertyValue))
                {
                    _propertyValueChangeNotificationWrappers[propertyName] = null;
                }
                else
                {
                    var wrapper = new ChangeNotificationWrapper(propertyValue);
                    wrapper.PropertyChanged               += OnPropertyObjectPropertyChanged;
                    wrapper.CollectionChanged             += OnPropertyObjectCollectionChanged;
                    wrapper.CollectionItemPropertyChanged += OnPropertyObjectCollectionItemPropertyChanged;
                    _propertyValueChangeNotificationWrappers[propertyName] = wrapper;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the object events subscription. This means that the old value will be removed from the event subscriptions, and
        /// the new value will be subscribed to.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="propertyValue">The property value.</param>
        private void HandleObjectEventsSubscription(string propertyName, object propertyValue)
        {
            if (DisableEventSubscriptionsOfChildValues)
            {
                return;
            }

            lock (_lock)
            {
                ChangeNotificationWrapper oldWrapper;

                if (_propertyValueChangeNotificationWrappers == null)
                {
                    _propertyValueChangeNotificationWrappers = new Dictionary <string, ChangeNotificationWrapper>();
                }

                if (_propertyValueChangeNotificationWrappers.TryGetValue(propertyName, out oldWrapper))
                {
                    oldWrapper.PropertyChanged               -= OnPropertyObjectPropertyChanged;
                    oldWrapper.CollectionChanged             -= OnPropertyObjectCollectionChanged;
                    oldWrapper.CollectionItemPropertyChanged -= OnPropertyObjectCollectionItemPropertyChanged;
                    oldWrapper.UnsubscribeFromAllEvents();
                }

                if (!ChangeNotificationWrapper.IsUsefulForObject(propertyValue))
                {
                    if (oldWrapper != null)
                    {
                        _propertyValueChangeNotificationWrappers.Remove(propertyName);
                    }
                }
                else
                {
                    var wrapper = new ChangeNotificationWrapper(propertyValue);
                    wrapper.PropertyChanged               += OnPropertyObjectPropertyChanged;
                    wrapper.CollectionChanged             += OnPropertyObjectCollectionChanged;
                    wrapper.CollectionItemPropertyChanged += OnPropertyObjectCollectionItemPropertyChanged;
                    _propertyValueChangeNotificationWrappers[propertyName] = wrapper;
                }
            }
        }