Expression.Parameter 方法

定义

创建可用于 ParameterExpression 标识表达式树中的参数或变量的节点。

重载

名称 说明
Parameter(Type, String)

创建可用于 ParameterExpression 标识表达式树中的参数或变量的节点。

Parameter(Type)

创建可用于 ParameterExpression 标识表达式树中的参数或变量的节点。

Parameter(Type, String)

创建可用于 ParameterExpression 标识表达式树中的参数或变量的节点。

public:
 static System::Linq::Expressions::ParameterExpression ^ Parameter(Type ^ type, System::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

参数

type
Type

参数或变量的类型。

name
String

参数或变量的名称,仅用于调试或打印目的。

返回

一个ParameterExpression属性NodeType等于ParameterTypeName属性设置为指定值。

例外

typenull

适用于

Parameter(Type)

创建可用于 ParameterExpression 标识表达式树中的参数或变量的节点。

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

参数

type
Type

参数或变量的类型。

返回

ParameterExpression具有指定名称和类型的节点。

示例

以下示例演示如何创建打印 MethodCallExpression 对象值 ParameterExpression 的对象。

// 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

适用于