using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ICSharpCode.Decompiler { static class CollectionExtensions { public static HashSet ToHashSet(this IEnumerable input) { return new HashSet(input); } public static T PopOrDefault(this Stack stack) { if (stack.Count == 0) return default(T); return stack.Pop(); } public static T PeekOrDefault(this Stack stack) { if (stack.Count == 0) return default(T); return stack.Peek(); } public static void AddRange(this ICollection collection, IEnumerable input) { foreach (T item in input) collection.Add(item); } /// /// Equivalent to collection.Select(func).ToArray(), but more efficient as it makes /// use of the input collection's known size. /// public static U[] SelectArray(this ICollection collection, Func func) { U[] result = new U[collection.Count]; int index = 0; foreach (var element in collection) { result[index++] = func(element); } return result; } } }