Core/Refactor: Part 3

This commit is contained in:
hondacrx
2018-05-16 19:57:48 -04:00
parent 225a5d27f7
commit 5dacd669b5
112 changed files with 564 additions and 561 deletions
+11 -8
View File
@@ -66,6 +66,9 @@ namespace System.Collections.Generic
}
public static KeyValuePair<TKey, TValue> Find<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
{
if (!dict.ContainsKey(key))
return default(KeyValuePair<TKey, TValue>);
return new KeyValuePair<TKey, TValue>(key, dict[key]);
}
@@ -113,17 +116,17 @@ namespace System.Collections.Generic
}
}
public static void RandomResize<T>(this ICollection<T> list, Predicate<T> predicate, uint size)
public static void RandomResize<T>(this List<T> list, Predicate<T> predicate, uint size)
{
List<T> listCopy = new List<T>();
foreach (var obj in list)
if (predicate(obj))
listCopy.Add(obj);
for (var i = 0; i < list.Count; ++i)
{
var obj = list[i];
if (!predicate(obj))
list.Remove(obj);
}
if (size != 0)
listCopy.Resize(size);
list = listCopy;
list.Resize(size);
}
public static T SelectRandom<T>(this IEnumerable<T> source)