ListInitExpression ListInitExpression ListInitExpression ListInitExpression Class

定義

コレクション初期化子を持つコンストラクター呼び出しを表します。Represents a constructor call that has a collection initializer.

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
継承
ListInitExpressionListInitExpressionListInitExpressionListInitExpression

次の例では、作成、ListInitExpressionを表す 2 つのキー/値ペアを含む新しいディクショナリのインスタンスを初期化します。The following example creates a ListInitExpression that represents the initialization of a new dictionary instance that has two key-value pairs.

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します。Use the ListInit factory methods to create a ListInitExpression.

値、NodeTypeのプロパティをListInitExpressionListInitします。The value of the NodeType property of a ListInitExpression is ListInit.

プロパティ

CanReduce CanReduce CanReduce CanReduce

式ツリー ノードを縮小できるかどうかを示す値を取得します。Gets a value that indicates whether the expression tree node can be reduced.

Initializers Initializers Initializers Initializers

コレクションの初期化に使用される要素の初期化子を取得します。Gets the element initializers that are used to initialize a collection.

NewExpression NewExpression NewExpression NewExpression

コレクション型のコンス トラクターの呼び出しを含む式を取得します。Gets the expression that contains a call to the constructor of a collection type.

NodeType NodeType NodeType NodeType

この Expression のノード型を返します。Returns the node type of this Expression.

Type Type Type Type

この Expression が表す式の静的な型を取得します。Gets the static type of the expression that this Expression represents.

メソッド

Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor)

このノード型の特定の Visit メソッドにデスパッチします。Dispatches to the specific visit method for this node type. たとえば、MethodCallExpressionVisitMethodCall(MethodCallExpression) を呼び出します。For example, MethodCallExpression calls the VisitMethodCall(MethodCallExpression).

(Inherited from Expression)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
Reduce() Reduce() Reduce() Reduce()

二項式ノードをより単純な式へと変形します。Reduces the binary expression node to a simpler expression.

ReduceAndCheck() ReduceAndCheck() ReduceAndCheck() ReduceAndCheck()

このノードをより単純な式に変形します。Reduces this node to a simpler expression. CanReduce が true を返す場合、これは有効な式を返します。If CanReduce returns true, this should return a valid expression. このメソッドは、それ自体も単純化する必要がある別のノードを返す場合があります。This method can return another node which itself must be reduced.

(Inherited from Expression)
ReduceExtensions() ReduceExtensions() ReduceExtensions() ReduceExtensions()

式を既知のノード型 (拡張ノードではない型) に単純化し、それが既に既知の型である場合は単に式を返します。Reduces the expression to a known node type (that is not an Extension node) or just returns the expression if it is already a known type.

(Inherited from Expression)
ToString() ToString() ToString() ToString()

Expression のテキスト表現を返します。Returns a textual representation of the Expression.

(Inherited from Expression)
Update(NewExpression, IEnumerable<ElementInit>) Update(NewExpression, IEnumerable<ElementInit>) Update(NewExpression, IEnumerable<ElementInit>) Update(NewExpression, IEnumerable<ElementInit>)

これに似た式ですが、指定された子を使用する、新しい式を作成します。Creates a new expression that is like this one, but using the supplied children. すべての子が同じである場合、この式を返します。If all of the children are the same, it will return this expression.

VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor)

ノードを単純化し、単純化された式の visitor デリゲートを呼び出します。Reduces the node and then calls the visitor delegate on the reduced expression. ノードを単純化できない場合、このメソッドは例外をスローします。The method throws an exception if the node is not reducible.

(Inherited from Expression)

適用対象