/// <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; } } }
/// <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; } } }