EnumerableHelpers
namespace System.Collections.Generic
{
internal static class EnumerableHelpers
{
internal static void Reset<T>(ref T enumerator) where T : IEnumerator
{
enumerator.Reset();
}
internal static IEnumerator<T> GetEmptyEnumerator<T>()
{
return ((IEnumerable<T>)Array.Empty<T>()).GetEnumerator();
}
internal static T[] ToArray<T>(IEnumerable<T> source, out int length)
{
ICollection<T> collection = source as ICollection<T>;
if (collection != null) {
int count = collection.Count;
if (count != 0) {
T[] array = new T[count];
collection.CopyTo(array, 0);
length = count;
return array;
}
} else {
using (IEnumerator<T> enumerator = source.GetEnumerator()) {
if (enumerator.MoveNext()) {
T[] array2 = new T[4] {
enumerator.Current,
default(T),
default(T),
default(T)
};
int num = 1;
while (enumerator.MoveNext()) {
if (num == array2.Length) {
int num2 = num << 1;
if ((uint)num2 > 2147483591)
num2 = ((2147483591 <= num) ? (num + 1) : 2147483591);
Array.Resize(ref array2, num2);
}
array2[num++] = enumerator.Current;
}
length = num;
return array2;
}
}
}
length = 0;
return Array.Empty<T>();
}
}
}