ParameterExpression 类

定义

表示一个命名的参数表达式。

public ref class ParameterExpression : System::Linq::Expressions::Expression
public ref class ParameterExpression sealed : System::Linq::Expressions::Expression
public class ParameterExpression : System.Linq.Expressions.Expression
public sealed class ParameterExpression : System.Linq.Expressions.Expression
type ParameterExpression = class
    inherit Expression
Public Class ParameterExpression
Inherits Expression
Public NotInheritable Class ParameterExpression
Inherits Expression
继承
ParameterExpression

示例

下面的示例演示如何创建一个MethodCallExpression使用Parameter该方法打印对象值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

注解

Parameter使用工厂方法创建一个 ParameterExpression

NodeType对象的属性值ParameterExpressionParameter.

属性

CanReduce

指示可将节点简化为更简单的节点。 如果返回 true,则可以调用 Reduce() 以生成简化形式。

(继承自 Expression)
IsByRef

指示此 ParameterExpression 将被视为 ByRef 参数。

Name

获取参数或变量的名称。

NodeType

返回此 Expression 的节点类型。

NodeType

获取此 Expression 的节点类型。

(继承自 Expression)
Type

获取此 Expression 表示的表达式的静态类型。

Type

获取此 Expression 表示的表达式的静态类型。

(继承自 Expression)

方法

Accept(ExpressionVisitor)

调度到此节点类型的特定 Visit 方法。 例如,MethodCallExpression 调用 VisitMethodCall(MethodCallExpression)

Accept(ExpressionVisitor)

调度到此节点类型的特定 Visit 方法。 例如,MethodCallExpression 调用 VisitMethodCall(MethodCallExpression)

(继承自 Expression)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Reduce()

将此节点简化为更简单的表达式。 如果 CanReduce 返回 true,则它应返回有效的表达式。 此方法可以返回本身必须简化的另一个节点。

(继承自 Expression)
ReduceAndCheck()

将此节点简化为更简单的表达式。 如果 CanReduce 返回 true,则它应返回有效的表达式。 此方法可以返回本身必须简化的另一个节点。

(继承自 Expression)
ReduceExtensions()

将表达式简化为已知节点类型(即非 Extension 节点)或仅在此类型为已知类型时返回表达式。

(继承自 Expression)
ToString()

返回 Expression 的的文本化表示形式。

(继承自 Expression)
VisitChildren(ExpressionVisitor)

简化节点,然后对简化的表达式调用访问者委托。 该方法在节点不可简化时引发异常。

(继承自 Expression)

适用于