Expression.Multiply 方法

定义

创建一个表示不进行溢出检查的算术乘法运算的 BinaryExpression

重载

Multiply(Expression, Expression, MethodInfo)

创建一个表示不进行溢出检查的算术乘法运算的 BinaryExpression

Multiply(Expression, Expression)

创建一个表示不进行溢出检查的算术乘法运算的 BinaryExpression

Multiply(Expression, Expression, MethodInfo)

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

创建一个表示不进行溢出检查的算术乘法运算的 BinaryExpression

public:
 static System::Linq::Expressions::BinaryExpression ^ Multiply(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.BinaryExpression Multiply (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.BinaryExpression Multiply (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo? method);
static member Multiply : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.BinaryExpression
Public Shared Function Multiply (left As Expression, right As Expression, method As MethodInfo) As BinaryExpression

参数

left
Expression

要将 Expression 属性设置为与其相等的 Left

right
Expression

要将 Expression 属性设置为与其相等的 Right

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

返回

一个 BinaryExpression,其 NodeType 属性等于 Multiply,并且其 LeftRightMethod 属性设置为指定值。

例外

leftrightnull

method 不是 null,它所表示的方法返回 void,而不是 static(Visual Basic 中为 Shared),或者并非采用两个参数。

methodnull,并且没有为 left.Type 和 right.Type 定义乘法运算符。

注解

生成的 BinaryExpressionMethod 属性设置为 实现方法。 属性 Type 设置为节点的类型。 如果节点已提升,则 IsLiftedIsLiftedToNull 属性均为 true。 否则,它们为 falseConversion 属性为 null

以下信息介绍了实现方法、节点类型以及是否提升节点。

实现方法

以下规则确定操作的实现方法:

  • 如果 method 不是 null ,并且它表示非 void, static (Shared Visual Basic) 方法中采用两个参数,则它是节点的实现方法。

  • 否则,如果 Typerightleft 属性表示重载乘法运算符的用户定义类型,MethodInfo则表示该方法的 就是实现方法。

  • 否则,如果 为 ,则为 left。键入 和 right。类型是数值类型,实现方法是 null

节点类型和提升与非提升

如果实现方法不是 null

  • 如果 left为 。键入 和 right。类型可分配给实现方法的相应参数类型,节点不会提升。 节点的类型是实现方法的返回类型。

  • 如果满足以下两个条件,则会提升节点,节点的类型是对应于实现方法的返回类型的可为空类型:

    • left.键入 和 right。类型是两种值类型,其中至少有一种可为 null,相应的不可为 null 类型等于实现方法的相应参数类型。

    • 实现方法的返回类型是不可为 null 的值类型。

如果实现方法是 null

  • 如果 left为 。键入 和 right。类型都是不可为 null 的,节点不会解除。 节点的类型是预定义乘法运算符的结果类型。

  • 如果 left为 。键入 和 right。类型都是可以为 null 的,节点是提升的。 节点的类型是对应于预定义乘法运算符的结果类型的可为空类型。

适用于

Multiply(Expression, Expression)

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

创建一个表示不进行溢出检查的算术乘法运算的 BinaryExpression

public:
 static System::Linq::Expressions::BinaryExpression ^ Multiply(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right);
public static System.Linq.Expressions.BinaryExpression Multiply (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right);
static member Multiply : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BinaryExpression
Public Shared Function Multiply (left As Expression, right As Expression) As BinaryExpression

参数

left
Expression

要将 Expression 属性设置为与其相等的 Left

right
Expression

要将 Expression 属性设置为与其相等的 Right

返回

一个 BinaryExpression,其 NodeType 属性等于 Multiply,并且其 LeftRight 属性设置为指定值。

例外

leftrightnull

没有为 left.Type 和 right.Type 定义乘法运算符。

示例

下面的代码示例演示如何创建一个将两个值相乘的表达式。

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

// This expression multiplies its two arguments.
// Both arguments must be of the same type.
Expression multiplyExpr = Expression.Multiply(
    Expression.Constant(10),
    Expression.Constant(4)
);

// Print out the expression.
Console.WriteLine(multiplyExpr.ToString());

// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(
    Expression.Lambda<Func<int>>(multiplyExpr).Compile()());

// This code example produces the following output:
//
// (10*4)
// 40
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' This expression multiplies its two arguments.
' Both arguments must be of the same type.
Dim multiplyExpr As Expression = Expression.Multiply(
    Expression.Constant(10),
    Expression.Constant(4)
)

' Print the expression.
Console.WriteLine(multiplyExpr.ToString())

' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(
    Expression.Lambda(Of Func(Of Integer))(multiplyExpr).Compile()())

' This code example produces the following output:
'
' (10*4)
' 40

注解

生成的 BinaryExpressionMethod 属性设置为 实现方法。 属性 Type 设置为节点的类型。 如果节点已提升,则 IsLiftedIsLiftedToNull 属性均为 true。 否则,它们为 falseConversion 属性为 null

以下信息介绍了实现方法、节点类型以及是否提升节点。

实现方法

以下规则确定操作的所选实现方法:

  • Type如果 或 rightleft 属性表示重载乘法运算符的用户定义类型,MethodInfo则表示该方法的 就是实现方法。

  • 否则,如果 为 ,则为 left。键入 和 right。类型是数值类型,实现方法是 null

节点类型和提升与非提升

如果实现方法不是 null

  • 如果 left为 。键入 和 right。类型可分配给实现方法的相应参数类型,节点不会提升。 节点的类型是实现方法的返回类型。

  • 如果满足以下两个条件,则会提升节点,节点的类型是对应于实现方法的返回类型的可为空类型:

    • left.键入 和 right。类型是两种值类型,其中至少有一种可为 null,相应的不可为 null 类型等于实现方法的相应参数类型。

    • 实现方法的返回类型是不可为 null 的值类型。

如果实现方法是 null

  • 如果 left为 。键入 和 right。类型都是不可为 null 的,节点不会解除。 节点的类型是预定义乘法运算符的结果类型。

  • 如果 left为 。键入 和 right。类型都是可以为 null 的,节点是提升的。 节点的类型是对应于预定义乘法运算符的结果类型的可为空类型。

适用于