private int GetInsertIndex(ObservableList <ProxyInfo> data, ProxyInfo proxy, PreventChangeSortingDirection preventor) { if (preventor.HasSorting) { int index = data.BinarySearch(proxy, new ProxyInfoComparer(preventor.SortMemberPath, preventor.SortDirection)); if (index < 0) { index = ~index; } if (index >= 0) { return(index); } } return(data.Count); }
private void UpdateFiltering <TKey>(ObservableList <FilterData> list, NotifyCollectionChangedEventArgs e, Func <ProxyInfo, TKey> keySelector) where TKey : IComparable { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (ProxyInfo proxy in e.NewItems) { TKey data = keySelector(proxy); FilterData filterData = new FilterData { Data = data }; int index = list.BinarySearch(filterData, new FilterDataComparer()); if (index < 0) { index = ~index; filterData.Count = 1; list.Insert(index, filterData); } else { list[index].Count++; } } break; case NotifyCollectionChangedAction.Remove: foreach (ProxyInfo proxy in e.OldItems) { int index = list.BinarySearch(new FilterData { Data = keySelector(proxy) }, new FilterDataComparer()); if (index >= 0) { if (list[index].Count == 1) { list.Remove(list[index]); } else { list[index].Count--; } } } break; case NotifyCollectionChangedAction.Reset: list.Clear(); break; default: throw new NotSupportedException(); } }