ElementInit Klasa

Definicja

Reprezentuje inicjator dla pojedynczego IEnumerable elementu kolekcji.

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
Dziedziczenie
ElementInit
Implementuje

Przykłady

Poniższy przykład tworzy obiekt ElementInit , który reprezentuje inicjowanie elementu kolekcji słowników.

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

Właściwości

AddMethod

Pobiera metodę wystąpienia używaną do dodawania elementu do IEnumerable kolekcji.

Arguments

Pobiera kolekcję argumentów przekazywanych do metody, która dodaje element do IEnumerable kolekcji.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca tekstową reprezentację ElementInit obiektu.

Update(IEnumerable<Expression>)

Tworzy nowe wyrażenie, które jest podobne do tego, ale przy użyciu dostarczonych elementów podrzędnych. Jeśli wszystkie elementy podrzędne są takie same, zwróci to wyrażenie.

Jawne implementacje interfejsu

IArgumentProvider.ArgumentCount

Zwraca liczbę argumentów do węzła drzewa wyrażeń. Nie należy używać tego elementu członkowskiego. Jest ona publiczna tylko ze względu na refaktoryzację zestawu i jest używana wewnętrznie do optymalizacji wydajności.

IArgumentProvider.GetArgument(Int32)

Zwraca argument w indeksie, zgłaszając, czy indeks jest poza granicami. Nie należy używać tego elementu członkowskiego. Jest ona publiczna tylko ze względu na refaktoryzację zestawu i jest używana wewnętrznie do optymalizacji wydajności.

Dotyczy