Catel.Data.ChangeNotificationWrapper.IsUsefulForObject C# (CSharp) Method

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
        public static bool IsUsefulForObject(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            if (obj is INotifyPropertyChanged)
            {
                return true;
            }

            if (obj is INotifyCollectionChanged)
            {
                return true;
            }

            return false;
        }

Usage Example

Example #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;
                }
            }
        }
All Usage Examples Of Catel.Data.ChangeNotificationWrapper::IsUsefulForObject