45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections;
|
||
|
|
using UnityEngine.TestTools;
|
||
|
|
|
||
|
|
namespace BracerLib.Utility
|
||
|
|
{
|
||
|
|
[ExcludeFromCoverage]
|
||
|
|
public static class ArrayExtensions
|
||
|
|
{
|
||
|
|
public static bool Contains<T>(this T[] array, T value) where T : IComparable
|
||
|
|
{
|
||
|
|
for (var i = 0; i < array.Length; i++)
|
||
|
|
{
|
||
|
|
if (array[i].CompareTo(value) == 0)
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static bool Contains<T, U>(this T[] array, U value, Func<T, U, bool> predicate)
|
||
|
|
{
|
||
|
|
for (var i = 0; i < array.Length; i++)
|
||
|
|
{
|
||
|
|
if (predicate(array[i], value))
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static T[] Subset<T>(this T[] data, int index, int length)
|
||
|
|
{
|
||
|
|
var result = new T[length];
|
||
|
|
Array.Copy(data, index, result, 0, length);
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static bool HasIndex(this IList list, int index) => index >= 0 && index < list.Count;
|
||
|
|
|
||
|
|
public static bool HasIndex(this Array array, int index) => index >= 0 && index < array.Length;
|
||
|
|
}
|
||
|
|
}
|