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

ParameterExpression と等しい NodeType プロパティと、指定した値に設定された Parameter プロパティおよび Type プロパティを含む Name

例外

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

指定した名前および型の 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

適用対象