/// <summary>
/// Creates an <see cref="IndexExpression"></see> to access an array.
/// </summary>
/// <param name="array">An expression representing the array to index.</param>
/// <param name="indexes">An <see cref="IEnumerable{Expression}"/> containing expressions used to index the array.</param>
/// <remarks>The expression representing the array can be obtained by using the MakeMemberAccess method,
/// or through NewArrayBounds or NewArrayInit.</remarks>
/// <returns>The created <see cref="IndexExpression"/>.</returns>
public static IndexExpression ArrayAccess(Expression array, IEnumerable <Expression> indexes)
{
RequiresCanRead(array, "array");
var arrayType = array.Type;
if (!arrayType.IsArray)
{
throw Error.ArgumentMustBeArray();
}
var indexList = indexes.ToReadOnly();
if (arrayType.GetArrayRank() != indexList.Count)
{
throw Error.IncorrectNumberOfIndexes();
}
foreach (var e in indexList)
{
RequiresCanRead(e, "indexes");
if (e.Type != typeof(int))
{
throw Error.ArgumentMustBeArrayIndexType();
}
}
return(new IndexExpression(array, null, indexList));
}