IndexExpression クラス

定義

プロパティまたは配列のインデックス化を表します。

public ref class IndexExpression sealed : System::Linq::Expressions::Expression, System::Linq::Expressions::IArgumentProvider
public ref class IndexExpression sealed : System::Linq::Expressions::Expression
public sealed class IndexExpression : System.Linq.Expressions.Expression, System.Linq.Expressions.IArgumentProvider
public sealed class IndexExpression : System.Linq.Expressions.Expression
type IndexExpression = class
    inherit Expression
    interface IArgumentProvider
type IndexExpression = class
    inherit Expression
Public NotInheritable Class IndexExpression
Inherits Expression
Implements IArgumentProvider
Public NotInheritable Class IndexExpression
Inherits Expression
継承
IndexExpression
実装

次のコード例は、 型の IndexExpression オブジェクトを作成し、それを使用して メソッドを使用して配列要素の値を変更する方法を ArrayAccess 示しています。

// Add the following directive to your file:
// using System.Linq.Expressions;

// This parameter expression represents a variable that will hold the array.
ParameterExpression arrayExpr = Expression.Parameter(typeof(int[]), "Array");

// This parameter expression represents an array index.
ParameterExpression indexExpr = Expression.Parameter(typeof(int), "Index");

// This parameter represents the value that will be added to a corresponding array element.
ParameterExpression valueExpr = Expression.Parameter(typeof(int), "Value");

// This expression represents an array access operation.
// It can be used for assigning to, or reading from, an array element.
Expression arrayAccessExpr = Expression.ArrayAccess(
    arrayExpr,
    indexExpr
);

// This lambda expression assigns a value provided to it to a specified array element.
// The array, the index of the array element, and the value to be added to the element
// are parameters of the lambda expression.
Expression<Func<int[], int, int, int>> lambdaExpr = Expression.Lambda<Func<int[], int, int, int>>(
    Expression.Assign(arrayAccessExpr, Expression.Add(arrayAccessExpr, valueExpr)),
    arrayExpr,
    indexExpr,
    valueExpr
);

// Print out expressions.
Console.WriteLine("Array Access Expression:");
Console.WriteLine(arrayAccessExpr.ToString());

Console.WriteLine("Lambda Expression:");
Console.WriteLine(lambdaExpr.ToString());

Console.WriteLine("The result of executing the lambda expression:");

// The following statement first creates an expression tree,
// then compiles it, and then executes it.
// Parameters passed to the Invoke method are passed to the lambda expression.
Console.WriteLine(lambdaExpr.Compile().Invoke(new int[] { 10, 20, 30 }, 0, 5));

// This code example produces the following output:
//
// Array Access Expression:
// Array[Index]

// Lambda Expression:
// (Array, Index, Value) => (Array[Index] = (Array[Index] + Value))

// The result of executing the lambda expression:
// 15
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' This parameter expression represents a variable that will hold the array.
Dim arrayExpr As ParameterExpression = Expression.Parameter(GetType(Integer()), "Array")

' This parameter expression represents an array index.
' For multidimensional arrays, you can define several indexes. 
Dim indexExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "Index")

' This parameter represents the value that will be added to a corresponding array element.
Dim valueExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "Value")

' This expression represents an array access operation.
' It can be used for assigning to, or reading from, an array element.
Dim arrayAccessExpr As Expression = Expression.ArrayAccess(
    arrayExpr,
    indexExpr
)

' This lambda expression assigns a value provided to it to a specified array element.
' The array, the index of the array element, and the value to be added to the element
' are parameters of the lambda expression.
Dim lambdaExpr As Expression(Of Func(Of Integer(), Integer, Integer, Integer)) =
    Expression.Lambda(Of Func(Of Integer(), Integer, Integer, Integer))(
        Expression.Assign(arrayAccessExpr, Expression.Add(arrayAccessExpr, valueExpr)),
    arrayExpr,
    indexExpr,
    valueExpr
  )

' Print expressions.
Console.WriteLine("Array Access Expression:")
Console.WriteLine(arrayAccessExpr.ToString())

Console.WriteLine("Lambda Expression:")
Console.WriteLine(lambdaExpr.ToString())

Console.WriteLine("The result of executing the lambda expression:")

' The following statement first creates an expression tree,
' then compiles it, and then executes it.
' Parameters passed to the Invoke method are passed to the lambda expression.
Console.WriteLine(lambdaExpr.Compile().Invoke(New Integer() {10, 20, 30}, 0, 5))

' This code example produces the following output:
'
' Array Access Expression:
' Array[Index]

' Lambda Expression:
' (Array, Index, Value) => (Array[Index] = (Array[Index] + Value))

' The result of executing the lambda expression:
' 15

プロパティ

Arguments

プロパティまたは配列のインデックス化に使用する引数を取得します。

CanReduce

ノードをより単純なノードに変形できることを示します。 これが true を返す場合、Reduce() を呼び出して単純化された形式を生成できます。

(継承元 Expression)
Indexer

式がインデックス付きのプロパティを表す場合は、PropertyInfo を取得します。それ以外の場合は、null を返します。

NodeType

この Expression のノード型を返します。

Object

インデックス化するオブジェクト。

Type

この Expression が表す式の静的な型を取得します。

メソッド

Accept(ExpressionVisitor)

このノード型の特定の Visit メソッドにデスパッチします。 たとえば、MethodCallExpressionVisitMethodCall(MethodCallExpression) を呼び出します。

(継承元 Expression)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
Reduce()

このノードをより単純な式に変形します。 CanReduce が true を返す場合、これは有効な式を返します。 このメソッドは、それ自体も単純化する必要がある別のノードを返す場合があります。

(継承元 Expression)
ReduceAndCheck()

このノードをより単純な式に変形します。 CanReduce が true を返す場合、これは有効な式を返します。 このメソッドは、それ自体も単純化する必要がある別のノードを返す場合があります。

(継承元 Expression)
ReduceExtensions()

式を既知のノード型 (拡張ノードではない型) に単純化し、それが既に既知の型である場合は単に式を返します。

(継承元 Expression)
ToString()

Expression のテキスト表現を返します。

(継承元 Expression)
Update(Expression, IEnumerable<Expression>)

これに似た式ですが、指定された子を使用する、新しい式を作成します。 すべての子が同じである場合、この式を返します。

VisitChildren(ExpressionVisitor)

ノードを単純化し、単純化された式の visitor デリゲートを呼び出します。 ノードを単純化できない場合、このメソッドは例外をスローします。

(継承元 Expression)

明示的なインターフェイスの実装

IArgumentProvider.ArgumentCount

式ツリー ノードに引数の数を返します。 このメンバーを使用しないでください。 これは、アセンブリ リファクタリングのためパブリックのみで、パフォーマンスの最適化のために内部で使用されます。

IArgumentProvider.GetArgument(Int32)

インデックスの引数を返し、インデックスが範囲外にある場合にスローします。 このメンバーを使用しないでください。 これは、アセンブリ リファクタリングのためパブリックのみで、パフォーマンスの最適化のために内部で使用されます。

適用対象