ElementInit Classe

Definição

Representa um inicializador para um único elemento de uma IEnumerable coleção.

public ref class ElementInit sealed : System::Linq::Expressions::IArgumentProvider
public ref class ElementInit sealed
public sealed class ElementInit : System.Linq.Expressions.IArgumentProvider
public sealed class ElementInit
type ElementInit = class
    interface IArgumentProvider
type ElementInit = class
Public NotInheritable Class ElementInit
Implements IArgumentProvider
Public NotInheritable Class ElementInit
Herança
ElementInit
Implementações

Exemplos

O exemplo a seguir cria um ElementInit que representa a inicialização de um elemento de uma coleção de dicionários.

string tree = "maple";

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

// Create an ElementInit that represents calling
// Dictionary<int, string>.Add(tree.Length, tree).
System.Linq.Expressions.ElementInit elementInit =
    System.Linq.Expressions.Expression.ElementInit(
        addMethod,
        System.Linq.Expressions.Expression.Constant(tree.Length),
        System.Linq.Expressions.Expression.Constant(tree));

Console.WriteLine(elementInit.ToString());

// This code produces the following output:
//
// Void Add(Int32, System.String)(5,"maple")
Dim tree As String = "maple"

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

' Create an ElementInit that represents calling
' Dictionary(Of Integer, String).Add(tree.Length, tree).
Dim elementInit As System.Linq.Expressions.ElementInit = _
    System.Linq.Expressions.Expression.ElementInit( _
        addMethod, _
        System.Linq.Expressions.Expression.Constant(tree.Length), _
        System.Linq.Expressions.Expression.Constant(tree))

Console.WriteLine(elementInit.ToString())

' This code produces the following output:
'
' Void Add(Int32, System.String)(5,"maple")

Propriedades

Nome Description
AddMethod

Obtém o método de instância usado para adicionar um elemento a uma IEnumerable coleção.

Arguments

Obtém a coleção de argumentos que são passados para um método que adiciona um elemento a uma coleção IEnumerable .

Métodos

Nome Description
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função hash predefinida.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
ToString()

Retorna uma representação textual de um ElementInit objeto.

Update(IEnumerable<Expression>)

Cria uma nova expressão semelhante a esta, mas usando os filhos fornecidos. Se todas as crianças forem iguais, ela retornará essa expressão.

Implantações explícitas de interface

Nome Description
IArgumentProvider.ArgumentCount

Retorna o número de argumentos para o nó da árvore de expressão. Você não deve usar este membro. Ele só é público devido à refatoração de assembly e é usado internamente para otimizações de desempenho.

IArgumentProvider.GetArgument(Int32)

Retorna o argumento no índice, gerando se o índice estiver fora dos limites. Você não deve usar este membro. Ele só é público devido à refatoração de assembly e é usado internamente para otimizações de desempenho.

Aplica-se a