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

예제

다음 예제에서는 두 개의 키-값 쌍이 있는 새 사전 instance 초기화를 나타내는 을 만듭니다ListInitExpression.

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합니다.

값을 NodeType 의 속성을 ListInitExpressionListInit합니다.

속성

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)

노드를 줄인 다음 줄인 식에서 방문자 대리자를 호출합니다. 이 메서드는 노드를 줄일 수 없으면 예외를 throw합니다.

(다음에서 상속됨 Expression)

적용 대상