public void CustomSort(TStringListSortCompare CompareFn) { if ((FForceSort || !Sorted) && Count > 1) { OnChanging(EventArgs.Empty); QuickSort(0, Count - 1, CompareFn); OnChanged(EventArgs.Empty); } }
// use default quicksort implementation of framework private void QuickSort(int L, int R, TStringListSortCompare CompareFn) { if (L != 0 || R != Count - 1) { throw new NotImplementedException(); // implement own quicksort someday? } int[] map = Enumerable.Range(0, Count).ToArray(); object[] objs = FList.ToArray(); Array.Sort(map, objs, new FuncComparer <int>((x, y) => CompareFn(this, x, y))); //var items = map.Select(i => new { key = GetKey(i), values = GetValues(i) }).ToArray(); //foreach (var item in items) //{ // if (item.values != null) // { // for (int i = 0; i < item.values.Length; i++) // { // base.Add(item.key, item.values[i]); // } // } // else // { // base.Add(item.key, null); // } //} //FList.AddRange(objs); string[] lines = new string[map.Length]; for (int i = 0; i < map.Length; i++) { lines[i] = Strings[map[i]]; } this.Clear(); for (int i = 0; i < lines.Length; i++) { AddObject(lines[i], objs[i]); } }