Sdílet prostřednictvím


Expression.ElementInit Metoda

Definice

Vytvoří ElementInit.

Přetížení

Name Description
ElementInit(MethodInfo, IEnumerable<Expression>)

Vytvoří jako ElementInitdruhý argument hodnotu , která je daná IEnumerable<T> jako druhý argument.

ElementInit(MethodInfo, Expression[])

Vytvoří jako ElementInitdruhý argument matici hodnot.

ElementInit(MethodInfo, IEnumerable<Expression>)

Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs

Vytvoří jako ElementInitdruhý argument hodnotu , která je daná IEnumerable<T> jako druhý argument.

public:
 static System::Linq::Expressions::ElementInit ^ ElementInit(System::Reflection::MethodInfo ^ addMethod, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.ElementInit ElementInit(System.Reflection.MethodInfo addMethod, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
static member ElementInit : System.Reflection.MethodInfo * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.ElementInit
Public Shared Function ElementInit (addMethod As MethodInfo, arguments As IEnumerable(Of Expression)) As ElementInit

Parametry

addMethod
MethodInfo

A MethodInfo nastavit AddMethod vlastnost rovná se.

arguments
IEnumerable<Expression>

Objekty IEnumerable<T>Expression , které mají nastavit Arguments vlastnost rovnající se.

Návraty

AddMethod Vlastnost ElementInit a Arguments vlastnosti nastavené na zadané hodnoty.

Výjimky

addMethod nebo arguments je null.

Metoda, která addMethod představuje, není pojmenována "Add" (nerozlišuje velká a malá písmena).

nebo

Metoda, která addMethod představuje není metodou instance.

nebo

arguments neobsahuje stejný počet prvků jako počet parametrů pro metodu, která addMethod představuje.

nebo

Vlastnost Type jednoho nebo více prvků arguments není možné přiřadit k typu odpovídajícího parametru metody, který addMethod představuje.

Příklady

Následující příklad ukazuje, jak použít metodu ElementInit(MethodInfo, Expression[]) k vytvoření ElementInit , který představuje volání Add metody inicializace elementu slovník kolekce.

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

Poznámky

Parametr addMethod musí představovat metodu instance s názvem Add (nerozlišující malá a velká písmena). Metoda add musí mít stejný počet parametrů jako počet prvků v arguments. Vlastnost Type každého prvku v arguments musí být přiřazena k typu odpovídající parametr metody add, případně po uvozování.

Poznámka:

Prvek bude citován pouze v případě, že odpovídající parametr metody je typu Expression. Uvozování znamená, že prvek je zabalený do Quote uzlu. Výsledný uzel je jehož UnaryExpressionOperand vlastnost je prvek arguments.

Platí pro

ElementInit(MethodInfo, Expression[])

Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs
Zdroj:
ElementInit.cs

Vytvoří jako ElementInitdruhý argument matici hodnot.

public:
 static System::Linq::Expressions::ElementInit ^ ElementInit(System::Reflection::MethodInfo ^ addMethod, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.ElementInit ElementInit(System.Reflection.MethodInfo addMethod, params System.Linq.Expressions.Expression[] arguments);
static member ElementInit : System.Reflection.MethodInfo * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.ElementInit
Public Shared Function ElementInit (addMethod As MethodInfo, ParamArray arguments As Expression()) As ElementInit

Parametry

addMethod
MethodInfo

A MethodInfo nastavit AddMethod vlastnost rovná se.

arguments
Expression[]

Pole Expression objektů, které nastaví Arguments vlastnost rovnající se.

Návraty

AddMethod Vlastnost ElementInit a Arguments vlastnosti nastavené na zadané hodnoty.

Výjimky

addMethod nebo arguments je null.

Metoda addMethod představuje není pojmenovaná "Add" (nerozlišuje velká a malá písmena).

nebo

Metoda addMethod představuje není metoda instance.

nebo

argumenty neobsahují stejný počet prvků jako počet parametrů pro metodu, která addMethod představuje.

nebo

Vlastnost Type jednoho nebo více prvků arguments není možné přiřadit k typu odpovídajícího parametru metody, který addMethod představuje.

Příklady

Následující příklad ukazuje, jak použít metodu ElementInit(MethodInfo, Expression[]) k vytvoření ElementInit , který představuje volání Add metody inicializace elementu slovník kolekce.

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

Poznámky

Parametr addMethod musí představovat metodu instance s názvem Add (nerozlišující malá a velká písmena). Metoda add musí mít stejný počet parametrů jako počet prvků v arguments. Vlastnost Type každého prvku v arguments musí být přiřazena k typu odpovídající parametr metody add, případně po uvozování.

Poznámka:

Prvek bude citován pouze v případě, že odpovídající parametr metody je typu Expression. Uvozování znamená, že prvek je zabalený do Quote uzlu. Výsledný uzel je jehož UnaryExpressionOperand vlastnost je prvek arguments.

Platí pro