fix CollectionHelper.sync_with_never_duplicate
This commit is contained in:
1 parent
28307b0681
commit
9dd6fc8832
1 file changed
+4
-8
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
@@ -14,16 +13,13 @@ namespace mbts.utils {
|
||||
public static void sync_with_never_duplicate<T>(ObservableCollection<T> dest, IEnumerable<T> src, IEqualityComparer<T> comp) {
|
||||
int i = 0;
|
||||
foreach (var val in src.empty_if_null()) {
|
||||
int curr_index = dest.TakeWhile(dval => !comp.Equals(dval, val)).Count();
|
||||
if (curr_index == dest.Count) {
|
||||
dest.Add(val);
|
||||
} else if (curr_index == i) {
|
||||
int curr_index = dest.IndexOf(val);
|
||||
if (curr_index == i) {
|
||||
continue;
|
||||
} else if (curr_index < dest.Count) {
|
||||
} else if (curr_index > 0 && curr_index < dest.Count) {
|
||||
dest.RemoveAt(curr_index);
|
||||
dest.Insert(i, val);
|
||||
}
|
||||
++i;
|
||||
dest.Insert(i++, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user