ListInitExpression Classe

Definição

Representa uma chamada de construtor com um inicializador de coleção.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
Herança
ListInitExpression

Exemplos

O exemplo a seguir cria um ListInitExpression que representa a inicialização de uma nova instância de dicionário que tem dois pares chave-valor.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")

Comentários

Use os ListInit métodos de fábrica para criar um ListInitExpression .Use the ListInit factory methods to create a ListInitExpression.

O valor da NodeType propriedade de a ListInitExpression é ListInit .The value of the NodeType property of a ListInitExpression is ListInit.

Propriedades

CanReduce

Obtém um valor que indica se o nó da árvore de expressão pode ser reduzido.Gets a value that indicates whether the expression tree node can be reduced.

CanReduce

Indica que o nó pode ser reduzido a um nó mais simples.Indicates that the node can be reduced to a simpler node. Se isso retornar verdadeiro, Reduce() poderá ser chamado para produzir a forma reduzida.If this returns true, Reduce() can be called to produce the reduced form.

(Herdado de Expression)
Initializers

Obtém os inicializadores de elemento usados para inicializar uma coleção.Gets the element initializers that are used to initialize a collection.

NewExpression

Obtém a expressão que contém uma chamada para o construtor de um tipo de coleção.Gets the expression that contains a call to the constructor of a collection type.

NodeType

Retorna o tipo de nó deste Expression.Returns the node type of this Expression.

NodeType

Obtém o tipo de nó deste Expression.Gets the node type of this Expression.

(Herdado de Expression)
Type

Obtém o tipo estático da expressão que esse Expression representa.Gets the static type of the expression that this Expression represents.

Type

Obtém o tipo estático da expressão que esse Expression representa.Gets the static type of the expression that this Expression represents.

(Herdado de Expression)

Métodos

Accept(ExpressionVisitor)

Expede o método específico de visita para esse tipo de nó.Dispatches to the specific visit method for this node type. Por exemplo, MethodCallExpression chama o VisitMethodCall(MethodCallExpression).For example, MethodCallExpression calls the VisitMethodCall(MethodCallExpression).

(Herdado de Expression)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
Reduce()

Reduz o nó de expressão binária para uma expressão mais simples.Reduces the binary expression node to a simpler expression.

Reduce()

Reduz esse nó a uma expressão mais simples.Reduces this node to a simpler expression. Se CanReduce retornar true, ele deverá retornar uma expressão válida.If CanReduce returns true, this should return a valid expression. Esse método pode retornar outro nó que também precisa ser reduzido.This method can return another node which itself must be reduced.

(Herdado de Expression)
ReduceAndCheck()

Reduz esse nó a uma expressão mais simples.Reduces this node to a simpler expression. Se CanReduce retornar true, ele deverá retornar uma expressão válida.If CanReduce returns true, this should return a valid expression. Esse método pode retornar outro nó que também precisa ser reduzido.This method can return another node which itself must be reduced.

(Herdado de Expression)
ReduceExtensions()

Reduz a expressão a um tipo de nó conhecido (que não é um nó de extensão) ou apenas retorna a expressão se ele já é um tipo conhecido.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.

(Herdado de Expression)
ToString()

Retorna uma representação textual de Expression.Returns a textual representation of the Expression.

(Herdado de Expression)
Update(NewExpression, IEnumerable<ElementInit>)

Cria uma nova expressão que é parecida com esta, mas usando os filhos fornecidos.Creates a new expression that is like this one, but using the supplied children. Se todos os filhos forem os mesmos, ela retornará esta expressão.If all of the children are the same, it will return this expression.

VisitChildren(ExpressionVisitor)

Reduz o nó e, em seguida, chama o delegado visitante na expressão reduzida.Reduces the node and then calls the visitor delegate on the reduced expression. O método gera uma exceção se o nó não é reduzível.The method throws an exception if the node is not reducible.

(Herdado de Expression)

Aplica-se a