Редагувати

Поділитися через


Expression.Lambda Method

Definition

Creates an expression tree that represents a lambda expression.

Overloads

Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression where the delegate type is known at compile time, with the name for the lambda, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

Lambda(Type, Expression, String, IEnumerable<ParameterExpression>)

Creates a LambdaExpression where the delegate type is known at compile time, with the name for the lambda, and an enumerable collection of parameter expressions.

Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type from the expression body, the name for the lambda, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

Lambda(Type, Expression, ParameterExpression[])

Creates a LambdaExpression where the delegate type is known at compile time, with an array of parameter expressions.

Lambda(Type, Expression, Boolean, ParameterExpression[])

Creates a LambdaExpression where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an array of parameter expressions.

Lambda(Expression, String, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type from the expression body, the name for the lambda, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

Lambda(Expression, Boolean, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type from the expression body, a parameter that indicates whether tail call optimization will be applied, and an array of parameter expressions. It can be used when the delegate type is not known at compile time.

Lambda(Expression, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type from the expression body, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

Lambda(Type, Expression, IEnumerable<ParameterExpression>)

Creates a LambdaExpression where the delegate type is known at compile time, with an enumerable collection of parameter expressions.

Lambda(Expression, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type from the expression body, and an array of parameter expressions. It can be used when the delegate type is not known at compile time.

Lambda(Expression, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type from the expression body, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time, with the name for the lambda, and an enumerable collection of parameter expressions.

Lambda<TDelegate>(Expression, Boolean, ParameterExpression[])

Creates an Expression<TDelegate> where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an array of parameter expressions.

Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time, with the name for the lambda, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

Lambda<TDelegate>(Expression, ParameterExpression[])

Creates an Expression<TDelegate> where the delegate type is known at compile time, with an array of parameter expressions.

Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time, with an enumerable collection of parameter expressions.

Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression where the delegate type is known at compile time, with the name for the lambda, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, System::String ^ name, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, string name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, string? name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * string * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, name As String, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

delegateType
Type

A Type representing the delegate signature for the lambda.

body
Expression

An Expression to set the Body property equal to.

name
String

The name for the lambda. Used for emitting debug information.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Type, Expression, String, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression where the delegate type is known at compile time, with the name for the lambda, and an enumerable collection of parameter expressions.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, System::String ^ name, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, string name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, string? name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * string * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, name As String, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

delegateType
Type

A Type representing the delegate signature for the lambda.

body
Expression

An Expression to set the Body property equal to.

name
String

The name for the lambda. Used for emitting debug information.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

delegateType
Type

A Type representing the delegate signature for the lambda.

body
Expression

An Expression to set the Body property equal to.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression by first constructing a delegate type from the expression body, the name for the lambda, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, string name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, string? name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * string * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, name As String, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

body
Expression

An Expression to set the Body property equal to.

name
String

The name for the lambda. Used for emitting debug information.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Type, Expression, ParameterExpression[])

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression where the delegate type is known at compile time, with an array of parameter expressions.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[] parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[]? parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, ParamArray parameters As ParameterExpression()) As LambdaExpression

Parameters

delegateType
Type

A Type that represents a delegate signature for the lambda.

body
Expression

An Expression to set the Body property equal to.

parameters
ParameterExpression[]

An array of ParameterExpression objects to use to populate the Parameters collection.

Returns

An object that represents a lambda expression which has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

delegateType or body is null.

-or-

One or more elements in parameters are null.

delegateType does not represent a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of the delegate type represented by delegateType.

-or-

parameters does not contain the same number of elements as the list of parameters for the delegate type represented by delegateType.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of the delegate type represented by delegateType.

Remarks

The object that is returned from this function is of type Expression<TDelegate>. The LambdaExpression type is used to represent the returned object because the concrete type of the lambda expression is not known at compile time.

The number of parameters for the delegate type represented by delegateType must equal the length of parameters.

The elements of parameters must be reference equal to the parameter expressions in body.

The Type property of the resulting object is equal to delegateType. If parameters is null, the Parameters property of the resulting object is an empty collection.

Applies to

Lambda(Type, Expression, Boolean, ParameterExpression[])

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an array of parameter expressions.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, bool tailCall, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[] parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[]? parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * bool * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, tailCall As Boolean, ParamArray parameters As ParameterExpression()) As LambdaExpression

Parameters

delegateType
Type

A Type representing the delegate signature for the lambda.

body
Expression

An Expression to set the Body property equal to.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
ParameterExpression[]

An array that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Expression, String, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression by first constructing a delegate type from the expression body, the name for the lambda, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, string name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, string? name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * string * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, name As String, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

body
Expression

An Expression to set the Body property equal to.

name
String

The name for the lambda. Used for emitting debug information.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Expression, Boolean, ParameterExpression[])

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression by first constructing a delegate type from the expression body, a parameter that indicates whether tail call optimization will be applied, and an array of parameter expressions. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[] parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[]? parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, tailCall As Boolean, ParamArray parameters As ParameterExpression()) As LambdaExpression

Parameters

body
Expression

An Expression to set the Body property equal to.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
ParameterExpression[]

An array that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Expression, Boolean, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression by first constructing a delegate type from the expression body, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

body
Expression

An Expression to set the Body property equal to.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda(Type, Expression, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression where the delegate type is known at compile time, with an enumerable collection of parameter expressions.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

delegateType
Type

A Type that represents a delegate signature for the lambda.

body
Expression

An Expression to set the Body property equal to.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An object that represents a lambda expression which has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

delegateType or body is null.

-or-

One or more elements in parameters are null.

delegateType does not represent a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of the delegate type represented by delegateType.

-or-

parameters does not contain the same number of elements as the list of parameters for the delegate type represented by delegateType.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of the delegate type represented by delegateType.

Examples

The following example demonstrates how to create an expression that represents a lambda expression that adds 1 to the passed argument.

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

// A parameter for the lambda expression.
ParameterExpression paramExpr = Expression.Parameter(typeof(int), "arg");

// This expression represents a lambda expression
// that adds 1 to the parameter value.
LambdaExpression lambdaExpr = Expression.Lambda(
    Expression.Add(
        paramExpr,
        Expression.Constant(1)
    ),
    new List<ParameterExpression>() { paramExpr }
);

// Print out the expression.
Console.WriteLine(lambdaExpr);

// Compile and run the lamda expression.
// The value of the parameter is 1.
Console.WriteLine(lambdaExpr.Compile().DynamicInvoke(1));

// This code example produces the following output:
//
// arg => (arg +1)
// 2
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' A parameter for the lambda expression.
Dim paramExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "arg")

' This expression represents a lambda expression
' that adds 1 to the parameter value.
Dim lambdaExpr As LambdaExpression = Expression.Lambda(
        Expression.Add(
            paramExpr,
            Expression.Constant(1)
        ),
        New List(Of ParameterExpression)() From {paramExpr}
    )

' Print out the expression.
Console.WriteLine(lambdaExpr)

' Compile and run the lamda expression.
' The value of the parameter is 1.
Console.WriteLine(lambdaExpr.Compile().DynamicInvoke(1))

' This code example produces the following output:
'
' arg => (arg +1)
' 2

Remarks

The object that is returned from this function is of type Expression<TDelegate>. The LambdaExpression type is used to represent the returned object because the concrete type of the lambda expression is not known at compile time.

The number of parameters for the delegate type represented bydelegateType must equal the length of parameters.

The elements of parameters must be reference equal to the parameter expressions in body.

The Type property of the resulting object is equal to delegateType. If parameters is null, the Parameters property of the resulting object is an empty collection.

Applies to

Lambda(Expression, ParameterExpression[])

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression by first constructing a delegate type from the expression body, and an array of parameter expressions. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[] parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[]? parameters);
static member Lambda : System.Linq.Expressions.Expression * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, ParamArray parameters As ParameterExpression()) As LambdaExpression

Parameters

body
Expression

An Expression to set the Body property equal to.

parameters
ParameterExpression[]

An array of ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

body is null.

-or-

One or more elements of parameters are null.

parameters contains more than sixteen elements.

Remarks

The parameters parameter must not have more than sixteen elements.

The elements of parameters must be reference equal to the parameter expressions in body.

This method constructs an appropriate delegate type from one of the System.Func generic delegates. It then passes the delegate type to one of the Lambda factory methods to create a LambdaExpression.

Applies to

Lambda(Expression, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates a LambdaExpression by first constructing a delegate type from the expression body, and an enumerable collection of parameter expressions. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression

Parameters

body
Expression

An Expression to set the Body property equal to.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates an Expression<TDelegate> where the delegate type is known at compile time, with the name for the lambda, and an enumerable collection of parameter expressions.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, string name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, string? name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * string * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, name As String, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)

Type Parameters

TDelegate

The delegate type.

Parameters

body
Expression

An Expression to set the Body property equal to.

name
String

The name of the lambda. Used for generating debugging information.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda<TDelegate>(Expression, Boolean, ParameterExpression[])

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates an Expression<TDelegate> where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an array of parameter expressions.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[] parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[]? parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, tailCall As Boolean, ParamArray parameters As ParameterExpression()) As Expression(Of TDelegate)

Type Parameters

TDelegate

The delegate type.

Parameters

body
Expression

An Expression to set the Body property equal to.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
ParameterExpression[]

An array that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates an Expression<TDelegate> where the delegate type is known at compile time, with the name for the lambda, a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, string name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, string? name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * string * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, name As String, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)

Type Parameters

TDelegate

The delegate type.

Parameters

body
Expression

An Expression to set the Body property equal to.

name
String

The name of the lambda. Used for generating debugging info.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to

Lambda<TDelegate>(Expression, ParameterExpression[])

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates an Expression<TDelegate> where the delegate type is known at compile time, with an array of parameter expressions.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[] parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[]? parameters);
static member Lambda : System.Linq.Expressions.Expression * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, ParamArray parameters As ParameterExpression()) As Expression(Of TDelegate)

Type Parameters

TDelegate

A delegate type.

Parameters

body
Expression

An Expression to set the Body property equal to.

parameters
ParameterExpression[]

An array of ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

body is null.

-or-

One or more elements in parameters are null.

TDelegate is not a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of TDelegate.

-or-

parameters does not contain the same number of elements as the list of parameters for TDelegate.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of TDelegate.

Remarks

The number of parameters for the delegate type TDelegate must equal the number of elements in parameters.

The elements of parameters must be reference equal to the parameter expressions inbody.

The Type property of the resulting object represents the type TDelegate. If parameters is null, the Parameters property of the resulting object is an empty collection.

Applies to

Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates an Expression<TDelegate> where the delegate type is known at compile time, with an enumerable collection of parameter expressions.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)

Type Parameters

TDelegate

A delegate type.

Parameters

body
Expression

An Expression to set the Body property equal to.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

body is null.

-or-

One or more elements in parameters are null.

TDelegate is not a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of TDelegate.

-or-

parameters does not contain the same number of elements as the list of parameters for TDelegate.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of TDelegate.

Remarks

The number of parameters for the delegate type TDelegate must equal the number of elements in parameters.

The elements of parameters must be reference equal to the parameter expressions in body.

The Type property of the resulting object represents the type TDelegate. If parameters is null, the Parameters property of the resulting object is an empty collection.

Applies to

Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>)

Source:
LambdaExpression.cs
Source:
LambdaExpression.cs
Source:
LambdaExpression.cs

Creates an Expression<TDelegate> where the delegate type is known at compile time, with a parameter that indicates whether tail call optimization will be applied, and an enumerable collection of parameter expressions.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)

Type Parameters

TDelegate

The delegate type.

Parameters

body
Expression

An Expression to set the Body property equal to.

tailCall
Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to