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

UpdateCollectionSubscriptions() public method

Updates all the collection subscriptions. This method is internally used when a notifiable collection raises the NotifyCollectionChangedAction.Reset event.
public UpdateCollectionSubscriptions ( ICollection collection ) : void
collection ICollection
return void
        public void UpdateCollectionSubscriptions(ICollection collection)
        {
            if (collection == null)
            {
                return;
            }

            lock (_lockObject)
            {
                List<WeakReference> collectionItems;
                if (_collectionItems.TryGetValue(collection, out collectionItems))
                {
                    var oldItems = collectionItems.ToArray();
                    foreach (var item in oldItems)
                    {
                        if (item.IsAlive)
                        {
                            var actualItem = item.Target;
                            UnsubscribeNotifyChangedEvents(actualItem, collection);
                        }
                    }

                    collectionItems.Clear();
                }

                var newItems = collection.Cast<object>().ToArray();
                foreach (var item in newItems)
                {
                    SubscribeNotifyChangedEvents(item, collection);
                }
            }
        }