IndexExpression クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
プロパティまたは配列のインデックス作成を表します。
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 型のオブジェクトを作成し、それを使用して、 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 メソッドにディスパッチします。 たとえば、 MethodCallExpression は VisitMethodCall(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) |
ノードを減らし、縮小された式でビジター デリゲートを呼び出します。 ノードが縮小できない場合、メソッドは例外をスローします。 (継承元 Expression) |
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| IArgumentProvider.ArgumentCount |
式ツリー ノードに対する引数の数を返します。 このメンバーは使用しないでください。 アセンブリのリファクタリングによってのみパブリックになり、パフォーマンスの最適化のために内部的に使用されます。 |
| IArgumentProvider.GetArgument(Int32) |
インデックスが範囲外の場合にスローする、インデックス位置の引数を返します。 このメンバーは使用しないでください。 アセンブリのリファクタリングによってのみパブリックになり、パフォーマンスの最適化のために内部的に使用されます。 |