Expression.MakeBinary Method

Definition

Creates a BinaryExpression by calling the appropriate factory method.

Overloads

MakeBinary(ExpressionType, Expression, Expression)

Creates a BinaryExpression, given the left and right operands, by calling an appropriate factory method.

MakeBinary(ExpressionType, Expression, Expression, Boolean, MethodInfo)

Creates a BinaryExpression, given the left operand, right operand and implementing method, by calling the appropriate factory method.

MakeBinary(ExpressionType, Expression, Expression, Boolean, MethodInfo, LambdaExpression)

Creates a BinaryExpression, given the left operand, right operand, implementing method and type conversion function, by calling the appropriate factory method.

MakeBinary(ExpressionType, Expression, Expression)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

Creates a BinaryExpression, given the left and right operands, by calling an appropriate factory method.

C#
public static System.Linq.Expressions.BinaryExpression MakeBinary(System.Linq.Expressions.ExpressionType binaryType, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right);

Parameters

binaryType
ExpressionType

The ExpressionType that specifies the type of binary operation.

left
Expression

An Expression that represents the left operand.

right
Expression

An Expression that represents the right operand.

Returns

The BinaryExpression that results from calling the appropriate factory method.

Exceptions

binaryType does not correspond to a binary expression node.

left or right is null.

Examples

The following example demonstrates how to use the MakeBinary(ExpressionType, Expression, Expression) method to create a BinaryExpression that represents the subtraction of one number from another.

C#
// Create a BinaryExpression that represents subtracting 14 from 53.
System.Linq.Expressions.BinaryExpression binaryExpression =
    System.Linq.Expressions.Expression.MakeBinary(
        System.Linq.Expressions.ExpressionType.Subtract,
        System.Linq.Expressions.Expression.Constant(53),
        System.Linq.Expressions.Expression.Constant(14));

Console.WriteLine(binaryExpression.ToString());

// This code produces the following output:
//
// (53 - 14)

Remarks

The binaryType parameter determines which BinaryExpression factory method this method calls. For example, if binaryType is Subtract, this method invokes Subtract.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

MakeBinary(ExpressionType, Expression, Expression, Boolean, MethodInfo)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

Creates a BinaryExpression, given the left operand, right operand and implementing method, by calling the appropriate factory method.

C#
public static System.Linq.Expressions.BinaryExpression MakeBinary(System.Linq.Expressions.ExpressionType binaryType, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, bool liftToNull, System.Reflection.MethodInfo method);
C#
public static System.Linq.Expressions.BinaryExpression MakeBinary(System.Linq.Expressions.ExpressionType binaryType, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, bool liftToNull, System.Reflection.MethodInfo? method);

Parameters

binaryType
ExpressionType

The ExpressionType that specifies the type of binary operation.

left
Expression

An Expression that represents the left operand.

right
Expression

An Expression that represents the right operand.

liftToNull
Boolean

true to set IsLiftedToNull to true; false to set IsLiftedToNull to false.

method
MethodInfo

A MethodInfo that specifies the implementing method.

Returns

The BinaryExpression that results from calling the appropriate factory method.

Exceptions

binaryType does not correspond to a binary expression node.

left or right is null.

Remarks

The binaryType parameter determines which BinaryExpression factory method this method will call. For example, if binaryType is Subtract, this method invokes Subtract. The liftToNull and method parameters are ignored if the appropriate factory method does not have a corresponding parameter.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

MakeBinary(ExpressionType, Expression, Expression, Boolean, MethodInfo, LambdaExpression)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

Creates a BinaryExpression, given the left operand, right operand, implementing method and type conversion function, by calling the appropriate factory method.

C#
public static System.Linq.Expressions.BinaryExpression MakeBinary(System.Linq.Expressions.ExpressionType binaryType, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, bool liftToNull, System.Reflection.MethodInfo method, System.Linq.Expressions.LambdaExpression conversion);
C#
public static System.Linq.Expressions.BinaryExpression MakeBinary(System.Linq.Expressions.ExpressionType binaryType, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, bool liftToNull, System.Reflection.MethodInfo? method, System.Linq.Expressions.LambdaExpression? conversion);

Parameters

binaryType
ExpressionType

The ExpressionType that specifies the type of binary operation.

left
Expression

An Expression that represents the left operand.

right
Expression

An Expression that represents the right operand.

liftToNull
Boolean

true to set IsLiftedToNull to true; false to set IsLiftedToNull to false.

method
MethodInfo

A MethodInfo that specifies the implementing method.

conversion
LambdaExpression

A LambdaExpression that represents a type conversion function. This parameter is used only if binaryType is Coalesce or compound assignment.

Returns

The BinaryExpression that results from calling the appropriate factory method.

Exceptions

binaryType does not correspond to a binary expression node.

left or right is null.

Remarks

The binaryType parameter determines which BinaryExpression factory method this method will call. For example, if binaryType is Subtract, this method invokes Subtract. The liftToNull, method and conversion parameters are ignored if the appropriate factory method does not have a corresponding parameter.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0