Expression.ElementInit Metoda

Definicja

Tworzy element ElementInit.

Przeciążenia

ElementInit(MethodInfo, IEnumerable<Expression>)

Tworzy element ElementInit, podany IEnumerable<T> jako drugi argument.

ElementInit(MethodInfo, Expression[])

Tworzy tablicę ElementInitwartości jako drugi argument.

ElementInit(MethodInfo, IEnumerable<Expression>)

Źródło:
ElementInit.cs
Źródło:
ElementInit.cs
Źródło:
ElementInit.cs

Tworzy element ElementInit, podany IEnumerable<T> jako drugi 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 , aby ustawić właściwość równą AddMethod .

arguments
IEnumerable<Expression>

Obiekt IEnumerable<T> zawierający Expression obiekty ustawiające właściwość równą Arguments .

Zwraca

Obiekt ElementInit z właściwościami AddMethod i Arguments ustawionymi na określone wartości.

Wyjątki

addMethod lub arguments ma wartość null.

Metoda, która reprezentuje, addMethod nie nosi nazwy "Add" (bez uwzględniania wielkości liter).

-lub-

Metoda, która reprezentuje, addMethod nie jest metodą wystąpienia.

-lub-

arguments nie zawiera tej samej liczby elementów, co liczba parametrów dla metody, która addMethod reprezentuje.

-lub-

Właściwość Type jednego lub większej liczby elementów arguments nie jest przypisywana do typu odpowiadającego mu parametru metody, która addMethod reprezentuje.

Przykłady

W poniższym przykładzie pokazano, jak użyć ElementInit(MethodInfo, Expression[]) metody do utworzenia obiektu ElementInit reprezentującego wywołanie Add metody w celu zainicjowania 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")

Uwagi

Parametr addMethod musi reprezentować metodę wystąpienia o nazwie "Add" (bez uwzględniania wielkości liter). Metoda add musi mieć taką samą liczbę parametrów jak liczba elementów w elemecie arguments. Właściwość Type każdego elementu w arguments pliku musi być przypisywana do typu odpowiedniego parametru metody add, prawdopodobnie po cudzysłów.

Uwaga

Element będzie cytowany tylko wtedy, gdy odpowiedni parametr metody jest typu Expression. Cudzysłów oznacza, że element jest owinięty w węźle Quote . Wynikowy UnaryExpression węzeł jest, którego Operand właściwość jest elementem arguments.

Dotyczy

ElementInit(MethodInfo, Expression[])

Źródło:
ElementInit.cs
Źródło:
ElementInit.cs
Źródło:
ElementInit.cs

Tworzy tablicę ElementInitwartości jako drugi argument.

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 , aby ustawić właściwość równą AddMethod .

arguments
Expression[]

Tablica Expression obiektów do ustawienia właściwości równej Arguments .

Zwraca

Obiekt ElementInit z właściwościami AddMethod i Arguments ustawionymi na określone wartości.

Wyjątki

addMethod lub arguments ma wartość null.

Metoda, która reprezentuje addMethod, nie nosi nazwy "Add" (bez uwzględniania wielkości liter).

-lub-

Metoda, która addMethod reprezentuje, nie jest metodą wystąpienia.

-lub-

argumenty nie zawierają tej samej liczby elementów, co liczba parametrów dla metody, która reprezentuje addMethod.

-lub-

Właściwość Type jednego lub większej liczby elementów arguments nie jest przypisywana do typu odpowiadającego mu parametru metody, która addMethod reprezentuje.

Przykłady

W poniższym przykładzie pokazano, jak użyć ElementInit(MethodInfo, Expression[]) metody do utworzenia obiektu ElementInit reprezentującego wywołanie Add metody w celu zainicjowania 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")

Uwagi

Parametr addMethod musi reprezentować metodę wystąpienia o nazwie "Add" (bez uwzględniania wielkości liter). Metoda add musi mieć taką samą liczbę parametrów jak liczba elementów w elemecie arguments. Właściwość Type każdego elementu w arguments pliku musi być przypisywana do typu odpowiedniego parametru metody add, prawdopodobnie po cudzysłów.

Uwaga

Element będzie cytowany tylko wtedy, gdy odpowiedni parametr metody jest typu Expression. Cudzysłów oznacza, że element jest owinięty w węźle Quote . Wynikowy UnaryExpression węzeł jest, którego Operand właściwość jest elementem arguments.

Dotyczy