DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="1.2.0" />

 Collection

public static class Collection
Provides utility methods to work with collections.
using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DotNext.Collections.Generic { public static class Collection { public static ReadOnlyCollectionView<I, O> Convert<I, O>(this IReadOnlyCollection<I> collection, [In] [System.Runtime.CompilerServices.IsReadOnly] ref ValueFunc<I, O> converter) { return new ReadOnlyCollectionView<I, O>(collection, ref converter); } public static ReadOnlyCollectionView<I, O> Convert<I, O>(this IReadOnlyCollection<I> collection, Converter<I, O> converter) { ValueFunc<I, O> converter2 = converter.AsValueFunc(true); return collection.Convert(ref converter2); } private static T[] ToArray<C, T>(C collection, int count) where C : class, IEnumerable<T> { T[] array = new T[count]; long num = 0; foreach (T item in (IEnumerable<T>)collection) { T[] array2 = array; long num2 = num; num = num2 + 1; array2[num2] = item; } return array; } public static T[] ToArray<T>(ICollection<T> collection) { return ToArray<ICollection<T>, T>(collection, collection.Count); } public static T[] ToArray<T>(IReadOnlyCollection<T> collection) { return ToArray<IReadOnlyCollection<T>, T>(collection, collection.Count); } public static void AddAll<T>(this ICollection<T> collection, IEnumerable<T> items) { items.ForEach(collection.Add); } } }