public void IsArrayOfType() { Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[], object>()); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[, ], object>()); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[, , ], object>()); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[, , , ], object>()); Assert.IsFalse(ArrayIdentification.IsArrayOfType <object[], int>()); Assert.IsFalse(ArrayIdentification.IsArrayOfType <object[], short>()); Assert.IsFalse(ArrayIdentification.IsArrayOfType <short[], int>()); Assert.IsTrue(ArrayIdentification.IsArrayOfType <int[], int>()); Assert.IsTrue(ArrayIdentification.IsArrayOfByte <byte[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfInt16 <short[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfInt32 <int[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfInt64 <long[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfSByte <sbyte[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfUInt16 <ushort[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfUInt32 <uint[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfUInt64 <ulong[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfSingle <float[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfDouble <double[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfDecimal <decimal[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfChar <char[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfBoolean <bool[]>()); Assert.IsTrue(ArrayIdentification.IsArrayOfString <string[]>()); }
public void IsJaggedArrayOfType() { Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[][], object>(2)); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[, ][], object>(2)); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[, ][, ], object>(2)); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[, ][, , , ], object>(2)); Assert.IsFalse(ArrayIdentification.IsArrayOfType <object[][][], object>(2)); Assert.IsFalse(ArrayIdentification.IsArrayOfType <object[][][][], object>(2)); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[][][][], object>(4)); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[][][][][], object>(6)); Assert.IsTrue(ArrayIdentification.IsArrayOfType <object[, , , ][, ][, , , ][, , , , , , ][, , ], object>(6)); }
public static bool IsArrayOfChar(this Array array) => ArrayIdentification.IsArrayOfType <char>(array.GetType());
public static bool IsArrayOfDecimal(this Array array) => ArrayIdentification.IsArrayOfType <decimal>(array.GetType());
public static bool IsArrayOfDouble(this Array array) => ArrayIdentification.IsArrayOfType <double>(array.GetType());
public static bool IsArrayOfSingle(this Array array) => ArrayIdentification.IsArrayOfType <float>(array.GetType());
public static bool IsArrayOfUInt64(this Array array) => ArrayIdentification.IsArrayOfType <ulong>(array.GetType());
/// <summary>Determines whether an array type contains elements of the provided type. It only checks for multidimensional arrays (of the form [(,)*]). Jagged arrays are not taken into consideration in this implementation. Also built as an extension method to allow per-instance call.</summary> /// <typeparam name="TElement">The type of the element the array stores.</typeparam> /// <param name="array">The array whose type to examine.</param> /// <returns>Whether the given array type stores elements of the <typeparamref name="TElement"/> type.</returns> public static bool IsArrayOfType <TElement>(this Array array) => ArrayIdentification.IsArrayOfType <TElement>(array.GetType());
public static bool IsArrayOfInt16(this Array array) => ArrayIdentification.IsArrayOfType <short>(array.GetType());
//[Benchmark] public void Array30D() => ArrayIdentification.IsArrayOfType <object[, , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], object>();
//[Arguments(6)] //[Arguments(10)] //[Arguments(25)] //[Arguments(32)] public void JaggedArray32x32x32x32x32D(int maxJaggingLevel) { ArrayIdentification.IsArrayOfType <object[, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ][, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ][, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ][, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ][, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], object>(maxJaggingLevel); }
//[Benchmark] public void JaggedArray6x5x4x3x2x1D() => ArrayIdentification.IsArrayOfType <object[, , , , , ][, , , , ][, , , ][, , ][, ][], object>(6);
//[Benchmark] public void JaggedArray1x2x3x4x5x6D() => ArrayIdentification.IsArrayOfType <object[][, ][, , ][, , , ][, , , , ][, , , , , ], object>(6);
//[Benchmark] public void JaggedArray1x1x1x1x1x1D() => ArrayIdentification.IsArrayOfType <object[][][][][][], object>(6);
public static bool IsArrayOfBoolean(this Array array) => ArrayIdentification.IsArrayOfType <bool>(array.GetType());
public static bool IsArrayOfString(this Array array) => ArrayIdentification.IsArrayOfType <string>(array.GetType());
public static bool IsArrayOfSByte(this Array array) => ArrayIdentification.IsArrayOfType <sbyte>(array.GetType());
/// <summary>Determines whether an array type contains elements of the provided type. It also checks for jagged arrays up to a maximum jagging level. Also built as an extension method to allow per-instance call.</summary> /// <typeparam name="TElement">The type of the element the array stores.</typeparam> /// <param name="array">The array whose type to examine.</param> /// <param name="maxJaggingLevel">The maximum jagging level of the array (1 means up to [], 2 means up to [][], etc.).</param> /// <returns>Whether the given array type stores elements of the <typeparamref name="TElement"/> type.</returns> public static bool IsArrayOfType <TElement>(this Array array, int maxJaggingLevel) => ArrayIdentification.IsArrayOfType <TElement>(array.GetType(), maxJaggingLevel);
public static bool IsArrayOfUInt32(this Array array) => ArrayIdentification.IsArrayOfType <uint>(array.GetType());