Expression.Parameter Método

Definición

Crea un nodo ParameterExpression que puede usarse para identificar un parámetro o una variable en un árbol de expresión.

Sobrecargas

Parameter(Type, String)

Crea un nodo ParameterExpression que puede usarse para identificar un parámetro o una variable en un árbol de expresión.

Parameter(Type)

Crea un nodo ParameterExpression que puede usarse para identificar un parámetro o una variable en un árbol de expresión.

Parameter(Type, String)

Crea un nodo ParameterExpression que puede usarse para identificar un parámetro o una variable en un árbol de expresión.

public:
 static System::Linq::Expressions::ParameterExpression ^ Parameter(Type ^ type, System::String ^ name);
public static System.Linq.Expressions.ParameterExpression Parameter (Type type, string name);
public static System.Linq.Expressions.ParameterExpression Parameter (Type type, string? name);
static member Parameter : Type * string -> System.Linq.Expressions.ParameterExpression
Public Shared Function Parameter (type As Type, name As String) As ParameterExpression

Parámetros

type
Type

Tipo del parámetro o variable.

name
String

Nombre del parámetro o variable; se emplea solo para depurar o imprimir.

Devoluciones

ParameterExpression

ParameterExpression cuya propiedad NodeType es Parameter y cuyas propiedades Type y Name se establecen en los valores especificados.

Excepciones

type es null.

Se aplica a

Parameter(Type)

Crea un nodo ParameterExpression que puede usarse para identificar un parámetro o una variable en un árbol de expresión.

public:
 static System::Linq::Expressions::ParameterExpression ^ Parameter(Type ^ type);
public static System.Linq.Expressions.ParameterExpression Parameter (Type type);
static member Parameter : Type -> System.Linq.Expressions.ParameterExpression
Public Shared Function Parameter (type As Type) As ParameterExpression

Parámetros

type
Type

Tipo del parámetro o variable.

Devoluciones

ParameterExpression

Crea un nodo ParameterExpression con el nombre y el tipo especificados.

Ejemplos

En el ejemplo siguiente se muestra cómo crear un MethodCallExpression objeto que imprime el valor de un ParameterExpression objeto .

// Add the following directive to the file:
// using System.Linq.Expressions;

// Creating a parameter for the expression tree.
ParameterExpression param = Expression.Parameter(typeof(int));

// Creating an expression for the method call and specifying its parameter.
MethodCallExpression methodCall = Expression.Call(
    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }),
    param
);

// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda<Action<int>>(
    methodCall,
    new ParameterExpression[] { param }
).Compile()(10);

// This code example produces the following output:
//
// 10
' Add the following directive to the file:
' Imports System.Linq.Expressions 

' Creating a parameter for the expression tree.
Dim param As ParameterExpression = Expression.Parameter(GetType(Integer))

' Creating an expression for the method call and specifying its parameter.
Dim methodCall As MethodCallExpression = Expression.Call(
        GetType(Console).GetMethod("WriteLine", New Type() {GetType(Integer)}),
        param
    )

' Compiling and invoking the methodCall expression.
Expression.Lambda(Of Action(Of Integer))(
    methodCall,
    New ParameterExpression() {param}
).Compile()(10)
' This code example produces the following output:
'
' 10

Se aplica a