ElementInit Třída

Definice

Představuje inicializátor pro jeden prvek IEnumerable kolekce.

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
Dědičnost
ElementInit
Implementuje

Příklady

Následující příklad vytvoří ElementInit , který představuje inicializaci prvku kolekce slovníku.

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

Vlastnosti

Name Description
AddMethod

Získá instanci metoda, která se používá k přidání elementu IEnumerable do kolekce.

Arguments

Získá kolekci argumentů, které jsou předány metodě, která přidává element do IEnumerable kolekce.

Metody

Name Description
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí textovou reprezentaci objektu ElementInit .

Update(IEnumerable<Expression>)

Vytvoří nový výraz, který je podobný tomuto, ale použije zadané podřízené položky. Pokud jsou všechny podřízené položky stejné, vrátí tento výraz.

Explicitní implementace rozhraní

Name Description
IArgumentProvider.ArgumentCount

Vrátí počet argumentů na uzel stromu výrazů. Tento člen byste neměli používat. Je veřejná pouze kvůli refaktoringu sestavení a používá se interně k optimalizacím výkonu.

IArgumentProvider.GetArgument(Int32)

Vrátí argument v indexu, který vyvolá, pokud je index mimo hranice. Tento člen byste neměli používat. Je veřejná pouze kvůli refaktoringu sestavení a používá se interně k optimalizacím výkonu.

Platí pro