Expression.NegateChecked 方法

定義

建立 UnaryExpression,其代表包含溢位檢查的算術負運算。Creates a UnaryExpression that represents an arithmetic negation operation that has overflow checking.

多載

NegateChecked(Expression)

建立 UnaryExpression,其代表包含溢位檢查的算術負運算。Creates a UnaryExpression that represents an arithmetic negation operation that has overflow checking.

NegateChecked(Expression, MethodInfo)

建立 UnaryExpression,其代表包含溢位檢查的算術負運算。Creates a UnaryExpression that represents an arithmetic negation operation that has overflow checking. 實作的方法可加以指定。The implementing method can be specified.

NegateChecked(Expression)

建立 UnaryExpression,其代表包含溢位檢查的算術負運算。Creates a UnaryExpression that represents an arithmetic negation operation that has overflow checking.

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

參數

expression
Expression

要將 Expression 屬性設定為與之相等的 OperandAn Expression to set the Operand property equal to.

傳回

UnaryExpression

UnaryExpression,其 NodeType 屬性等於 NegateChecked,而 Operand 屬性設定為指定的值。A UnaryExpression that has the NodeType property equal to NegateChecked and the Operand property set to the specified value.

例外狀況

expressionnullexpression is null.

不會為 expression.Type 定義一元減號運算子。The unary minus 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 minus 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.

適用於

NegateChecked(Expression, MethodInfo)

建立 UnaryExpression,其代表包含溢位檢查的算術負運算。Creates a UnaryExpression that represents an arithmetic negation operation that has overflow checking. 實作的方法可加以指定。The implementing method can be specified.

public:
 static System::Linq::Expressions::UnaryExpression ^ NegateChecked(System::Linq::Expressions::Expression ^ expression, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.UnaryExpression NegateChecked (System.Linq.Expressions.Expression expression, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.UnaryExpression NegateChecked (System.Linq.Expressions.Expression expression, System.Reflection.MethodInfo? method);
static member NegateChecked : System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.UnaryExpression
Public Shared Function NegateChecked (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 屬性等於 NegateChecked,且 OperandMethod 屬性設定為指定的值。A UnaryExpression that has the NodeType property equal to NegateChecked 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 minus 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 而它代表非 void, 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 minus 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.

適用於