public static MethodCallExpression ArrayIndex(Expression array, IEnumerable<Expression> indexes)
{
RequiresCanRead(array, nameof(array));
ContractUtils.RequiresNotNull(indexes, nameof(indexes));
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();
}
for (int i = 0, n = indexList.Count; i < n; i++)
{
Expression e = indexList[i];
RequiresCanRead(e, nameof(indexes), i);
if (e.Type != typeof(int))
{
throw Error.ArgumentMustBeArrayIndexType(nameof(indexes), i);
}
}
MethodInfo mi = array.Type.GetMethod("Get", BindingFlags.Public | BindingFlags.Instance);
return Call(array, mi, indexList);
}