Expression.UnaryPlus 方法

定义

创建一个表示一元正运算的 UnaryExpressionCreates a UnaryExpression that represents a unary plus operation.

重载

UnaryPlus(Expression, MethodInfo)

创建一个表示一元正运算的 UnaryExpressionCreates a UnaryExpression that represents a unary plus operation.

UnaryPlus(Expression)

创建一个表示一元正运算的 UnaryExpressionCreates a UnaryExpression that represents a unary plus operation.

UnaryPlus(Expression, MethodInfo)

创建一个表示一元正运算的 UnaryExpressionCreates a UnaryExpression that represents a unary plus operation.

public:
 static System::Linq::Expressions::UnaryExpression ^ UnaryPlus(System::Linq::Expressions::Expression ^ expression, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.UnaryExpression UnaryPlus (System.Linq.Expressions.Expression expression, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.UnaryExpression UnaryPlus (System.Linq.Expressions.Expression expression, System.Reflection.MethodInfo? method);
static member UnaryPlus : System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.UnaryExpression
Public Shared Function UnaryPlus (expression As Expression, method As MethodInfo) As UnaryExpression

参数

expression
Expression

要将 Expression 属性设置为与其相等的 OperandAn Expression to set the Operand property equal to.

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 MethodA MethodInfo to set the Method property equal to.

返回

UnaryExpression

一个 UnaryExpression,其 NodeType 属性等于 UnaryPlus,并且其 OperandMethod 属性设置为指定值。A UnaryExpression that has the NodeType property equal to UnaryPlus and the Operand and Method properties set to the specified values.

例外

expressionnullexpression is null.

method 不为 null 且其表示的方法返回 void;不为 static(在 Visual Basic 中不为 Shared);或者不是正好带一个参数。method is not null and the method it represents returns void, is not static (Shared in Visual Basic), or does not take exactly one argument.

methodnull,并且没有为 expression.Type 定义一元正运算符。method is null and the unary plus operator is not defined for expression.Type.

- 或 --or- expression.Type(如果它是可以为 null 的值类型,则取其相应的不可以为 null 的类型)不能赋给 method 所表示的方法的参数类型。expression.Type (or its corresponding non-nullable type if it is a nullable value type) is not assignable to the argument type of the method represented by method.

注解

生成的的 Method 属性 UnaryExpression 设置为实现方法。The Method property of the resulting UnaryExpression is set to the implementing method. Type属性设置为节点的类型。The Type property is set to the type of the node. 如果节点已提升,则 IsLiftedIsLiftedToNull 属性都为 trueIf the node is lifted, the IsLifted and IsLiftedToNull properties are both true. 否则为 false。Otherwise, they are false.

实现方法Implementing Method

以下规则确定操作的实现方法:The following rules determine the implementing method for the operation:

  • 如果不 method 为, null 并且它表示 static (Shared 采用一个自变量 Visual Basic) 方法,则它是节点的实现方法。If method is not null and it represents a non-void, static (Shared in Visual Basic) method that takes one argument, it is the implementing method for the node.

  • 如果为 expression 。类型是定义一元加运算符的用户定义类型,表示该运算符的 MethodInfo 是实现方法。If expression.Type is a user-defined type that defines the unary plus operator, the MethodInfo that represents that operator is the implementing method.

  • 否则,如果为 expression 。类型是数值类型,则实现方法为 nullOtherwise, if expression.Type is a numeric type, the implementing method is null.

节点类型和提升和非提升Node Type and Lifted versus Non-Lifted

如果实现方法不是 nullIf the implementing method is not null:

  • 如果为 expression 。类型可赋给实现方法的参数类型,不会提升节点。If expression.Type is assignable to the argument type of the implementing method, the node is not lifted. 节点的类型是实现方法的返回类型。The type of the node is the return type of the implementing method.

  • 如果满足以下两个条件,则会提升节点,并且该节点的类型为与实现方法的返回类型对应的可以为 null 的类型:If the following two conditions are satisfied, the node is lifted and the type of the node is the nullable type that corresponds to the return type of the implementing method:

    • expression.类型是可以为 null 的值类型,并且相应的不可为 null 的值类型等于实现方法的参数类型。expression.Type is a nullable value type and the corresponding non-nullable value type is equal to the argument type of the implementing method.

    • 实现方法的返回类型是不可为 null 的值类型。The return type of the implementing method is a non-nullable value type.

如果实现方法为 null ,则节点的类型为 expression 。类别.If the implementing method is null, the type of the node is expression.Type. 如果为 expression 。类型不可为 null,则不提升节点。If expression.Type is non-nullable, the node is not lifted. 否则,节点会提升。Otherwise, the node is lifted.

适用于

UnaryPlus(Expression)

创建一个表示一元正运算的 UnaryExpressionCreates a UnaryExpression that represents a unary plus operation.

public:
 static System::Linq::Expressions::UnaryExpression ^ UnaryPlus(System::Linq::Expressions::Expression ^ expression);
public static System.Linq.Expressions.UnaryExpression UnaryPlus (System.Linq.Expressions.Expression expression);
static member UnaryPlus : System.Linq.Expressions.Expression -> System.Linq.Expressions.UnaryExpression
Public Shared Function UnaryPlus (expression As Expression) As UnaryExpression

参数

expression
Expression

要将 Expression 属性设置为与其相等的 OperandAn Expression to set the Operand property equal to.

返回

UnaryExpression

一个 UnaryExpression,其 NodeType 属性等于 UnaryPlus,并且其 Operand 属性设置为指定值。A UnaryExpression that has the NodeType property equal to UnaryPlus and the Operand property set to the specified value.

例外

expressionnullexpression is null.

没有为 expression.Type 定义一元正运算符。The unary plus operator is not defined for expression.Type.

注解

生成的的 Method 属性 UnaryExpression 设置为实现方法。The Method property of the resulting UnaryExpression is set to the implementing method. Type属性设置为节点的类型。The Type property is set to the type of the node. 如果节点已提升,则 IsLiftedIsLiftedToNull 属性都为 trueIf the node is lifted, the IsLifted and IsLiftedToNull properties are both true. 否则为 false。Otherwise, they are false.

实现方法Implementing Method

以下规则确定操作的实现方法:The following rules determine the implementing method for the operation:

  • 如果为 expression 。类型是定义一元加运算符的用户定义类型,表示该运算符的 MethodInfo 是实现方法。If expression.Type is a user-defined type that defines the unary plus operator, the MethodInfo that represents that operator is the implementing method.

  • 否则,如果为 expression 。类型是数值类型,则实现方法为 nullOtherwise, if expression.Type is a numeric type, the implementing method is null.

节点类型和提升和非提升Node Type and Lifted versus Non-Lifted

如果实现方法不是 nullIf the implementing method is not null:

  • 如果为 expression 。类型可赋给实现方法的参数类型,不会提升节点。If expression.Type is assignable to the argument type of the implementing method, the node is not lifted. 节点的类型是实现方法的返回类型。The type of the node is the return type of the implementing method.

  • 如果满足以下两个条件,则会提升节点,并且该节点的类型为与实现方法的返回类型对应的可以为 null 的类型:If the following two conditions are satisfied, the node is lifted and the type of the node is the nullable type that corresponds to the return type of the implementing method:

    • expression.类型是可以为 null 的值类型,并且相应的不可为 null 的值类型等于实现方法的参数类型。expression.Type is a nullable value type and the corresponding non-nullable value type is equal to the argument type of the implementing method.

    • 实现方法的返回类型是不可为 null 的值类型。The return type of the implementing method is a non-nullable value type.

如果实现方法为 null ,则节点的类型为 expression 。类别.If the implementing method is null, the type of the node is expression.Type. 如果为 expression 。类型不可为 null,则不提升节点。If expression.Type is non-nullable, the node is not lifted. 否则,节点会提升。Otherwise, the node is lifted.

适用于