32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
using System;
|
|
|
|
namespace Microsoft.MixedReality.Toolkit
|
|
{
|
|
/// <summary>
|
|
/// <see cref="System.Array"/> type method extensions.
|
|
/// </summary>
|
|
public static class ArrayExtensions
|
|
{
|
|
/// <summary>
|
|
/// Wraps the index around to the beginning of the array if the provided index is longer than the array.
|
|
/// </summary>
|
|
/// <param name="array">The array to wrap the index around.</param>
|
|
/// <param name="index">The index to look for.</param>
|
|
public static int WrapIndex(this Array array, int index)
|
|
{
|
|
int length = array.Length;
|
|
return ((index % length) + length) % length;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether the given array is not null and has at least one entry
|
|
/// </summary>
|
|
public static bool IsValidArray(this Array array)
|
|
{
|
|
return array != null && array.Length > 0;
|
|
}
|
|
}
|
|
} |