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

OnObjectCollectionChanged() public method

Called when the target object raises the INotifyCollectionChanged.CollectionChanged event.
This method is public to allow the usage of the WeakEventListener, do not call this method yourself.
public OnObjectCollectionChanged ( object sender, NotifyCollectionChangedEventArgs e ) : void
sender object The sender.
e System.Collections.Specialized.NotifyCollectionChangedEventArgs The instance containing the event data.
return void
        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);
        }