public static BinaryExpression ArrayIndex(Expression array, Expression index)
{
RequiresCanRead(array, nameof(array));
RequiresCanRead(index, nameof(index));
if (index.Type != typeof(int))
{
throw Error.ArgumentMustBeArrayIndexType(nameof(index));
}
Type arrayType = array.Type;
if (!arrayType.IsArray)
{
throw Error.ArgumentMustBeArray(nameof(array));
}
if (arrayType.GetArrayRank() != 1)
{
throw Error.IncorrectNumberOfIndexes();
}
return new SimpleBinaryExpression(ExpressionType.ArrayIndex, array, index, arrayType.GetElementType());
}