public void Add(T obj) { T OldRemovedObj; if (EqualityComparer != null) { OldRemovedObj = (from removed in RemovedList where EqualityComparer.Equals(removed, obj) select removed).FirstOrDefault(); } else { OldRemovedObj = (from removed in RemovedList where removed.Equals(obj) select removed).FirstOrDefault(); } if (OldRemovedObj != null) { RemovedList.Remove(OldRemovedObj); ResultingList.Add(OldRemovedObj); } else { AddedList.Add(obj); ResultingList.Add(obj); } }
private void ChangedList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.NewItems != null && e.NewItems.Count != 0) { foreach (T obj in e.NewItems) { T OldAddedObj; OldAddedObj = (from added in AddedList where EqualityComparer.Equals(added, obj) select added).FirstOrDefault(); if (OldAddedObj != null) { AddedList.Remove(OldAddedObj); } else { ResultingList.Add(obj); } } } if (e.OldItems != null && e.OldItems.Count != 0) { foreach (T obj in e.OldItems) { T OldRemovedObj; OldRemovedObj = (from removed in RemovedList where EqualityComparer.Equals(removed, obj) select removed).FirstOrDefault(); if (OldRemovedObj != null) { RemovedList.Remove(OldRemovedObj); } else { ResultingList.Remove(obj); } } } if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset) { ResultingList.Clear(); RemovedList.Clear(); foreach (T obj in AddedList) { ResultingList.Add(obj); } } }
void CalculateResultingList() { ResultingList.Clear(); foreach (T obj in ChangedList) { ResultingList.Add(obj); } foreach (T obj in RemovedList) { ResultingList.Remove(obj); } foreach (T obj in AddedList) { ResultingList.Add(obj); } }
private void ChangedList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.NewItems != null && e.NewItems.Count != 0) { foreach (T obj in e.NewItems) { if (AddedList.Contains <T>(obj)) { List <int> positions = AddedList.FindAll(obj); T FoundObj = AddedList.ElementAt(positions[0]); AddedList.Remove(FoundObj); } else { ResultingList.Add(obj); } } } if (e.OldItems != null && e.OldItems.Count != 0) { foreach (T obj in e.OldItems) { if (RemovedList.Contains <T>(obj)) { List <int> positions = RemovedList.FindAll(obj); T FoundObj = RemovedList.ElementAt(positions[0]); RemovedList.Remove(FoundObj); } else { List <int> positions = ResultingList.FindAll(obj); T FoundObj = ResultingList.ElementAt(positions[0]); ResultingList.Remove(FoundObj); } } } if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset) { ResultingList.Clear(); RemovedList.Clear(); foreach (T obj in AddedList) { ResultingList.Add(obj); } } }