public void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
var collection = sender as ICollection;
lock (_lockObject)
{
if (e.OldItems != null)
{
foreach (var item in e.OldItems)
{
UnsubscribeNotifyChangedEvents(item, collection);
}
}
// Reset requires our own logic
if (e.Action == NotifyCollectionChangedAction.Reset)
{
if (collection != null)
{
UpdateCollectionSubscriptions(collection);
}
else
{
Log.Warning("Received NotifyCollectionChangedAction.Reset for '{0}', but the type does not implement ICollection", sender.GetType().GetSafeFullName(false));
}
}
else if (e.NewItems != null)
{
foreach (var item in e.NewItems)
{
SubscribeNotifyChangedEvents(item, collection);
}
}
}
CollectionChanged.SafeInvoke(sender, e);
}