public static ArrayAccess ( |
||
array | An expression representing the array to index. | |
indexes | IEnumerable |
An |
return |
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);
}
Expression::ArrayAccess ( |
public void ArrayAccess() { var expected = LinqExpression.ArrayAccess( LinqExpression.Parameter( typeof(int[])), LinqExpression.Parameter( typeof(int))); using var g = new GraphEngine.Graph(); g.LoadFromString(@" @prefix : <http://example.com/> . :s :arrayAccessArray [ :parameterType [ :typeName ""System.Int32[]"" ; ] ; ] ; :arrayAccessIndexes ( [ :parameterType [ :typeName ""System.Int32"" ; ] ; ] ) ; . "); var s = g.GetUriNode(":s"); var actual = Expression.Parse(s).LinqExpression; Console.WriteLine(actual.GetDebugView()); actual.Should().Be(expected); }