CollectionExtensions
using Stashbox.Entity;
using Stashbox.Utils;
using System.Linq.Expressions;
namespace System.Collections.Generic
{
internal static class CollectionExtensions
{
public static int GetIndex<TElement>(this TElement[] array, TElement element)
{
if (array == null || array.Length == 0)
return -1;
int num = array.Length;
if (num == 1) {
if (!array[0].Equals(element))
return -1;
return 0;
}
for (int i = 0; i < num; i++) {
if (array[i].Equals(element))
return i;
}
return -1;
}
public static int GetIndex<TKey, TValue>(this KeyValue<TKey, TValue>[] array, TKey element)
{
if (array == null || array.Length == 0)
return -1;
int num = array.Length;
TKey key;
if (num == 1) {
key = array[0].Key;
if (!key.Equals(element))
return -1;
return 0;
}
for (int i = 0; i < num; i++) {
key = array[i].Key;
if (key.Equals(element))
return i;
}
return -1;
}
public static bool ContainsElement<TElement>(this TElement[] array, TElement element)
{
return array.GetIndex(element) != -1;
}
public static Type[] GetTypes(this IList<ParameterExpression> parameters)
{
int count = parameters.Count;
switch (count) {
case 0:
return Constants.EmptyTypes;
case 1:
return new Type[1] {
parameters[0].Type
};
default: {
Type[] array = new Type[count];
for (int i = 0; i < count; i++) {
array[i] = parameters[i].Type;
}
return array;
}
}
}
public static Type[] Append(this Type type, Type[] types)
{
int num = types.Length;
if (num == 0)
return new Type[1] {
type
};
Type[] array = new Type[num + 1];
array[0] = type;
Array.Copy(types, 0, array, 1, num);
return array;
}
public static Type[] Append(this Type[] types, Type type)
{
int num = types.Length;
if (num == 0)
return new Type[1] {
type
};
Type[] array = new Type[num + 1];
Array.Copy(types, 0, array, 0, num);
array[num] = type;
return array;
}
public static Type[] Append(this Type[] types, Type[] others)
{
if (others.Length == 0)
return types;
if (types.Length == 0)
return others;
Type[] array = new Type[others.Length + types.Length];
Array.Copy(types, 0, array, 0, types.Length);
Array.Copy(others, 0, array, types.Length, others.Length);
return array;
}
}
}