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