CollectionExtensions
using System.Runtime.CompilerServices;
namespace System.Collections.Generic
{
internal static class CollectionExtensions
{
[NullableContext(1)]
internal static List<T> CreateTrimmedList<[Nullable(2)] T>(this IReadOnlyList<T> readOnlyList, int count)
{
ArgumentOutOfRangeException.ThrowIfLessThan(((IReadOnlyCollection<T>)readOnlyList).Count, count, "count");
T[] array = readOnlyList as T[];
if (array != null)
return new List<T>((IEnumerable<T>)new ArraySegment<T>(array, 0, count));
List<T> list = new List<T>((IEnumerable<T>)readOnlyList);
list.RemoveRange(count, list.Count - count);
return list;
}
}
}