ListInitExpression クラス

定義

コレクション初期化子を持つコンストラクター呼び出しを表します。

public ref class ListInitExpression sealed : System::Linq::Expressions::Expression
public sealed class ListInitExpression : System.Linq.Expressions.Expression
type ListInitExpression = class
    inherit Expression
Public NotInheritable Class ListInitExpression
Inherits Expression
継承
ListInitExpression

次の例では、 ListInitExpression 2 つのキーと値のペアを持つ新しいディクショナリ インスタンスの初期化を表す を作成します。

string tree1 = "maple";
string tree2 = "oak";

System.Reflection.MethodInfo addMethod = typeof(Dictionary<int, string>).GetMethod("Add");

// Create two ElementInit objects that represent the
// two key-value pairs to add to the Dictionary.
System.Linq.Expressions.ElementInit elementInit1 =
    System.Linq.Expressions.Expression.ElementInit(
        addMethod,
        System.Linq.Expressions.Expression.Constant(tree1.Length),
        System.Linq.Expressions.Expression.Constant(tree1));
System.Linq.Expressions.ElementInit elementInit2 =
    System.Linq.Expressions.Expression.ElementInit(
        addMethod,
        System.Linq.Expressions.Expression.Constant(tree2.Length),
        System.Linq.Expressions.Expression.Constant(tree2));

// Create a NewExpression that represents constructing
// a new instance of Dictionary<int, string>.
System.Linq.Expressions.NewExpression newDictionaryExpression =
    System.Linq.Expressions.Expression.New(typeof(Dictionary<int, string>));

// Create a ListInitExpression that represents initializing
// a new Dictionary<> instance with two key-value pairs.
System.Linq.Expressions.ListInitExpression listInitExpression =
    System.Linq.Expressions.Expression.ListInit(
        newDictionaryExpression,
        elementInit1,
        elementInit2);

Console.WriteLine(listInitExpression.ToString());

// This code produces the following output:
//
// new Dictionary`2() {Void Add(Int32, System.String)(5,"maple"),
// Void Add(Int32, System.String)(3,"oak")}
Dim tree1 As String = "maple"
Dim tree2 As String = "oak"

Dim addMethod As System.Reflection.MethodInfo = _
    Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]").GetMethod("Add")

' Create two ElementInit objects that represent the
' two key-value pairs to add to the Dictionary.
Dim elementInit1 As System.Linq.Expressions.ElementInit = _
    System.Linq.Expressions.Expression.ElementInit( _
        addMethod, _
        System.Linq.Expressions.Expression.Constant(tree1.Length), _
        System.Linq.Expressions.Expression.Constant(tree1))
Dim elementInit2 As System.Linq.Expressions.ElementInit = _
    System.Linq.Expressions.Expression.ElementInit( _
        addMethod, _
        System.Linq.Expressions.Expression.Constant(tree2.Length), _
        System.Linq.Expressions.Expression.Constant(tree2))

' Create a NewExpression that represents constructing
' a new instance of Dictionary(Of Integer, String).
Dim newDictionaryExpression As System.Linq.Expressions.NewExpression = _
    System.Linq.Expressions.Expression.[New](Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]"))

' Create a ListInitExpression that represents initializing
' a new Dictionary(Of T) instance with two key-value pairs.
Dim listInitExpression As System.Linq.Expressions.ListInitExpression = _
    System.Linq.Expressions.Expression.ListInit( _
        newDictionaryExpression, _
        elementInit1, _
        elementInit2)

Console.WriteLine(listInitExpression.ToString())

' This code produces the following output:
'
' new Dictionary`2() {Void Add(Int32, System.String)(5,"maple"),
' Void Add(Int32, System.String)(3,"oak")

注釈

ファクトリ メソッドを ListInit 使用して を作成します ListInitExpression

の プロパティListInitExpressionNodeType値は ですListInit

プロパティ

CanReduce

式ツリー ノードを縮小できるかどうかを示す値を取得します。

CanReduce

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

(継承元 Expression)
Initializers

コレクションの初期化に使用される要素初期化子を取得します。

NewExpression

コレクション型のコンストラクターへの呼び出しを含む式を取得します。

NodeType

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

NodeType

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

(継承元 Expression)
Type

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

Type

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

(継承元 Expression)

メソッド

Accept(ExpressionVisitor)

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

(継承元 Expression)
Equals(Object)

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

(継承元 Object)
GetHashCode()

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

(継承元 Object)
GetType()

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

(継承元 Object)
MemberwiseClone()

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

(継承元 Object)
Reduce()

二項式ノードをより単純な式へと変形します。

Reduce()

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

(継承元 Expression)
ReduceAndCheck()

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

(継承元 Expression)
ReduceExtensions()

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

(継承元 Expression)
ToString()

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

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

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

VisitChildren(ExpressionVisitor)

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

(継承元 Expression)

適用対象