public static IndexExpression ArrayAccess(Expression array, IEnumerable<Expression> indexes)
{
RequiresCanRead(array, nameof(array));
Type arrayType = array.Type;
if (!arrayType.IsArray)
{
throw Error.ArgumentMustBeArray(nameof(array));
}
ReadOnlyCollection<Expression> indexList = indexes.ToReadOnly();
if (arrayType.GetArrayRank() != indexList.Count)
{
throw Error.IncorrectNumberOfIndexes();
}
foreach (Expression e in indexList)
{
RequiresCanRead(e, nameof(indexes));
if (e.Type != typeof(int))
{
throw Error.ArgumentMustBeArrayIndexType(nameof(indexes));
}
}
return new IndexExpression(array, null, indexList);
}