DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="2.1.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 { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public static class Collection { [System.Runtime.CompilerServices.NullableContext(2)] [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1 })] public static ReadOnlyCollectionView<I, O> Convert<I, O>([System.Runtime.CompilerServices.Nullable(1)] this IReadOnlyCollection<I> collection, [In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1 })] ref ValueFunc<I, O> converter) { return new ReadOnlyCollectionView<I, O>(collection, ref converter); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1 })] public static ReadOnlyCollectionView<I, O> Convert<[System.Runtime.CompilerServices.Nullable(2)] I, [System.Runtime.CompilerServices.Nullable(2)] 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, [System.Runtime.CompilerServices.Nullable(2)] 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<[System.Runtime.CompilerServices.Nullable(2)] T>(ICollection<T> collection) { return ToArray<ICollection<T>, T>(collection, collection.Count); } public static T[] ToArray<[System.Runtime.CompilerServices.Nullable(2)] T>(IReadOnlyCollection<T> collection) { return ToArray<IReadOnlyCollection<T>, T>(collection, collection.Count); } public static void AddAll<[System.Runtime.CompilerServices.Nullable(2)] T>(this ICollection<T> collection, IEnumerable<T> items) { items.ForEach(collection.Add); } } }