Expression.Parameter Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a ParameterExpression node that can be used to identify a parameter or a variable in an expression tree.
Overloads
Parameter(Type, String) |
Creates a ParameterExpression node that can be used to identify a parameter or a variable in an expression tree. |
Parameter(Type) |
Creates a ParameterExpression node that can be used to identify a parameter or a variable in an expression tree. |
Parameter(Type, String)
- Source:
- ParameterExpression.cs
- Source:
- ParameterExpression.cs
- Source:
- ParameterExpression.cs
Creates a ParameterExpression node that can be used to identify a parameter or a variable in an expression tree.
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
Parameters
- type
- Type
The type of the parameter or variable.
- name
- String
The name of the parameter or variable, used for debugging or printing purpose only.
Returns
A ParameterExpression that has the NodeType property equal to Parameter and the Type and Name properties set to the specified values.
Exceptions
type
is null
.
Applies to
Parameter(Type)
- Source:
- ParameterExpression.cs
- Source:
- ParameterExpression.cs
- Source:
- ParameterExpression.cs
Creates a ParameterExpression node that can be used to identify a parameter or a variable in an expression tree.
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
Parameters
- type
- Type
The type of the parameter or variable.
Returns
A ParameterExpression node with the specified name and type.
Examples
The following example demonstrates how to create a MethodCallExpression object that prints the value of a ParameterExpression object.
// 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