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