EnumerableExtensions
using Stashbox.Utils.Data;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
namespace System.Linq
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
internal static class EnumerableExtensions
{
public static TEnumerable[] CastToArray<[System.Runtime.CompilerServices.Nullable(2)] TEnumerable>(this IEnumerable<TEnumerable> enumerable)
{
TEnumerable[] array = enumerable as TEnumerable[];
if (array == null)
return enumerable.ToArray();
return array;
}
public static T[] Append<[System.Runtime.CompilerServices.Nullable(2)] T>(this T[] array, T item)
{
int num = array.Length;
if (num == 0)
return new T[1] {
item
};
T[] array2 = new T[num + 1];
Array.Copy(array, array2, num);
array2[num] = item;
return array2;
}
public static bool ContainsReference<TElement>(this TElement[] array, TElement element) where TElement : class
{
return array.GetReferenceIndex(element) != -1;
}
public static int GetReferenceIndex<TElement>(this TElement[] array, TElement element) where TElement : class
{
if (array.Length == 0)
return -1;
int num = array.Length;
if (num == 1) {
if (array[0] != element)
return -1;
return 0;
}
for (int i = 0; i < num; i++) {
if (array[i] == element)
return i;
}
return -1;
}
public static TResult LastElement<[System.Runtime.CompilerServices.Nullable(2)] TResult>(this TResult[] source)
{
return source[source.Length - 1];
}
public static ParameterExpression[] AsParameters(this Type[] source)
{
int num = source.Length;
ParameterExpression[] array = new ParameterExpression[num];
for (int i = 0; i < num; i++) {
array[i] = source[i].AsParameter(null);
}
return array;
}
public static Pair<bool, ParameterExpression>[] AsParameterPairs(this ParameterExpression[] source)
{
int num = source.Length;
Pair<bool, ParameterExpression>[] array = new Pair<bool, ParameterExpression>[num];
for (int i = 0; i < num; i++) {
array[i] = new Pair<bool, ParameterExpression>(false, source[i]);
}
return array;
}
public static Stashbox.Utils.Data.Stack<TItem> AsStack<[System.Runtime.CompilerServices.Nullable(2)] TItem>(this IEnumerable<TItem> enumerable)
{
return Stashbox.Utils.Data.Stack<TItem>.FromEnumerable(enumerable);
}
}
}