ElementInit Clase

Definición

Representa un inicializador para un solo elemento de una colección IEnumerable.

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
Herencia
ElementInit
Implementaciones

Ejemplos

En el ejemplo siguiente se crea un ElementInit objeto que representa la inicialización de un elemento de una colección de diccionarios.

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")

Propiedades

AddMethod

Obtiene el método de instancia que se usa para agregar un elemento a una colección IEnumerable.

Arguments

Obtiene la colección de argumentos que se pasan a un método que agrega un elemento a una colección IEnumerable.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una representación textual de un objeto ElementInit.

Update(IEnumerable<Expression>)

Crea una nueva expresión que es como esta, pero usa el elemento secundario proporcionado. Si todos los elementos secundarios son iguales, devolverá esta expresión.

Implementaciones de interfaz explícitas

IArgumentProvider.ArgumentCount

Devuelve el número de argumentos al nodo de árbol de expresión. No debe usar este miembro. Solo es público debido a la refactorización del ensamblado y se usa internamente para optimizaciones de rendimiento.

IArgumentProvider.GetArgument(Int32)

Devuelve el argumento en el índice, indicando si el índice está fuera de los límites. No debe usar este miembro. Solo es público debido a la refactorización del ensamblado y se usa internamente para optimizaciones de rendimiento.

Se aplica a