private void SourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Move) { return; } if (e.Action != NotifyCollectionChangedAction.Reset) { if (e.OldItems != null) { var removed = new List <T>(); foreach (T item in e.OldItems) { TaggedObservableValue <bool, ItemMultiplicity> lambdaResult; if (isValueType || item != null) { if (lambdas.TryGetValue(item, out lambdaResult)) { if (lambdaResult.Value) { removed.Add(lambdaResult.Tag.Item); } lambdaResult.Tag = lambdaResult.Tag.Decrease(); if (lambdaResult.Tag.Multiplicity == 0) { lambdaResult.ValueChanged -= LambdaChanged; lambdaResult.Detach(); lambdas.Remove(item); } } else { //throw new InvalidOperationException(); } } else { nulls--; if (nulls == 0) { nullCheck.Detach(); nullCheck = null; } removed.Add(default(T)); } } OnRemoveItems(removed); } if (e.NewItems != null) { var added = new List <T>(); foreach (T item in e.NewItems) { var lambdaResult = AttachItem(item); if (lambdaResult.Value) { added.Add(item); } } OnAddItems(added); } } else { DetachSource(); OnCleared(); } }
protected virtual void DetachItem(TSource item, INotifyValue <TLambdaResult> lambdaValue) { lambdaValue.Detach(); }