Expression.Add Método
Definição
Cria um BinaryExpression que representa uma operação aritmética de adição que não tem verificação de estouro.Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking.
Sobrecargas
| Add(Expression, Expression) |
Cria um BinaryExpression que representa uma operação aritmética de adição que não tem verificação de estouro.Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking. |
| Add(Expression, Expression, MethodInfo) |
Cria um BinaryExpression que representa uma operação aritmética de adição que não tem verificação de estouro.Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking. O método de implementação pode ser especificado.The implementing method can be specified. |
Add(Expression, Expression)
Cria um BinaryExpression que representa uma operação aritmética de adição que não tem verificação de estouro.Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking.
public:
static System::Linq::Expressions::BinaryExpression ^ Add(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right);
public static System.Linq.Expressions.BinaryExpression Add (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right);
static member Add : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BinaryExpression
Public Shared Function Add (left As Expression, right As Expression) As BinaryExpression
Parâmetros
- left
- Expression
Um Expression para definir a propriedade Left igual a ele.A Expression to set the Left property equal to.
- right
- Expression
Um Expression para definir a propriedade Right igual a ele.A Expression to set the Right property equal to.
Retornos
Um BinaryExpression que tem a propriedade NodeType igual a Add e as propriedades Left e Right definidas com os valores especificados.A BinaryExpression that has the NodeType property equal to Add and the Left and Right properties set to the specified values.
Exceções
left ou right é null.left or right is null.
O operador de adição não foi definido para left.Type e right.Type.The addition operator is not defined for left.Type and right.Type.
Exemplos
O exemplo de código a seguir mostra como criar uma expressão que adiciona dois inteiros.The following code example shows how to create an expression that adds two integers.
// Add the following directive to your file:
// using System.Linq.Expressions;
// This expression adds the values of its two arguments.
// Both arguments must be of the same type.
Expression sumExpr = Expression.Add(
Expression.Constant(1),
Expression.Constant(2)
);
// Print out the expression.
Console.WriteLine(sumExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<int>>(sumExpr).Compile()());
// This code example produces the following output:
//
// (1 + 2)
// 3
' Add the following directive to your file:
' Imports System.Linq.Expressions
' This expression adds the values of its two arguments.
' Both arguments must be of the same type.
Dim sumExpr As Expression = Expression.Add(
Expression.Constant(1),
Expression.Constant(2)
)
' Print the expression.
Console.WriteLine(sumExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(sumExpr).Compile()())
' This code example produces the following output:
'
' (1 + 2)
' 3
Comentários
O resultado BinaryExpression tem a Method propriedade definida como o método de implementação.The resulting BinaryExpression has the Method property set to the implementing method. A Type propriedade é definida como o tipo do nó.The Type property is set to the type of the node. Se o nó for levantado, as IsLifted IsLiftedToNull Propriedades e serão ambas true .If the node is lifted, the IsLifted and IsLiftedToNull properties are both true. Caso contrário, eles são false .Otherwise, they are false. A propriedade Conversion é null.The Conversion property is null.
As informações a seguir descrevem o método de implementação, o tipo de nó e se um nó é levantado.The following information describes the implementing method, the node type, and whether a node is lifted.
Implementando métodoImplementing Method
As regras a seguir determinam o método de implementação selecionado para a operação:The following rules determine the selected implementing method for the operation:
Se a Type propriedade de
leftourightrepresentar um tipo definido pelo usuário que sobrecarrega o operador de adição, o MethodInfo que representa esse método é o método de implementação.If the Type property of eitherleftorrightrepresents a user-defined type that overloads the addition operator, the MethodInfo that represents that method is the implementing method.Caso contrário, se
left. Digite eright. Tipo são tipos numéricos, o método de implementação énull.Otherwise, ifleft.Type andright.Type are numeric types, the implementing method isnull.
Tipo de nó e versão com comparação de precisão x sem comparação de precisãoNode Type and Lifted versus Non-Lifted
Se o método de implementação não for null :If the implementing method is not null:
Se
left. Digite eright. O tipo pode ser atribuído aos tipos de argumento correspondentes do método de implementação, o nó não é levantado.Ifleft.Type andright.Type are assignable to the corresponding argument types of the implementing method, the node is not lifted. O tipo do nó é o tipo de retorno do método de implementação.The type of the node is the return type of the implementing method.Se as duas condições a seguir forem satisfeitas, o nó será levantado e o tipo do nó será o tipo anulável que corresponde ao tipo de retorno do método de implementação: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:
left. Digite eright. O tipo são ambos os tipos de valor dos quais pelo menos um é anulável e os tipos não anuláveis correspondentes são iguais aos tipos de argumento correspondentes do método de implementação.left.Type andright.Type are both value types of which at least one is nullable and the corresponding non-nullable types are equal to the corresponding argument types of the implementing method.O tipo de retorno do método de implementação é um tipo de valor não anulável.The return type of the implementing method is a non-nullable value type.
Se o método de implementação for null :If the implementing method is null:
Se
left. Digite eright. Os tipos são não anuláveis, o nó não é retirado.Ifleft.Type andright.Type are both non-nullable, the node is not lifted. O tipo do nó é o tipo de resultado do operador de adição predefinido.The type of the node is the result type of the predefined addition operator.Se
left. Digite eright. Os tipos são anuláveis, o nó é levantado.Ifleft.Type andright.Type are both nullable, the node is lifted. O tipo do nó é o tipo anulável que corresponde ao tipo de resultado do operador de adição predefinido.The type of the node is the nullable type that corresponds to the result type of the predefined addition operator.
Aplica-se a
Add(Expression, Expression, MethodInfo)
Cria um BinaryExpression que representa uma operação aritmética de adição que não tem verificação de estouro.Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking. O método de implementação pode ser especificado.The implementing method can be specified.
public:
static System::Linq::Expressions::BinaryExpression ^ Add(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.BinaryExpression Add (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.BinaryExpression Add (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo? method);
static member Add : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.BinaryExpression
Public Shared Function Add (left As Expression, right As Expression, method As MethodInfo) As BinaryExpression
Parâmetros
- left
- Expression
Um Expression para definir a propriedade Left igual a ele.A Expression to set the Left property equal to.
- right
- Expression
Um Expression para definir a propriedade Right igual a ele.A Expression to set the Right property equal to.
- method
- MethodInfo
Um MethodInfo para definir a propriedade Method igual a ele.A MethodInfo to set the Method property equal to.
Retornos
Um BinaryExpression que tem a propriedade NodeType igual a Add e as propriedades Left, Right e Method definidas para os valores especificados.A BinaryExpression that has the NodeType property equal to Add and the Left, Right and Method properties set to the specified values.
Exceções
left ou right é null.left or right is null.
method não é null e o método que ele representa retorna void, não é static (Shared no Visual Basic) ou não tem exatamente dois argumentos.method is not null and the method it represents returns void, is not static (Shared in Visual Basic), or does not take exactly two arguments.
method é null e o operador de adição não foi definido para left.Type e right.Type.method is null and the addition operator is not defined for left.Type and right.Type.
Comentários
O resultado BinaryExpression tem a Method propriedade definida como o método de implementação.The resulting BinaryExpression has the Method property set to the implementing method. A Type propriedade é definida como o tipo do nó.The Type property is set to the type of the node. Se o nó for levantado, as IsLifted IsLiftedToNull Propriedades e serão ambas true .If the node is lifted, the IsLifted and IsLiftedToNull properties are both true. Caso contrário, eles são false .Otherwise, they are false. A propriedade Conversion é null.The Conversion property is null.
As informações a seguir descrevem o método de implementação, o tipo de nó e se um nó é levantado.The following information describes the implementing method, the node type, and whether a node is lifted.
Implementando métodoImplementing Method
As regras a seguir determinam o método de implementação para a operação:The following rules determine the implementing method for the operation:
Se
methodnão fornulle representar um método que não seja voidstatic(Sharedno Visual Basic) que usa dois argumentos, ele será o método de implementação para o nó.Ifmethodis notnulland it represents a non-void,static(Sharedin Visual Basic) method that takes two arguments, it is the implementing method for the node.Caso contrário, se a Type propriedade de
leftourightrepresentar um tipo definido pelo usuário que sobrecarrega o operador de adição, o MethodInfo que representa esse método é o método de implementação.Otherwise, if the Type property of eitherleftorrightrepresents a user-defined type that overloads the addition operator, the MethodInfo that represents that method is the implementing method.Caso contrário, se
left. Digite eright. Tipo são tipos numéricos, o método de implementação énull.Otherwise, ifleft.Type andright.Type are numeric types, the implementing method isnull.
Tipo de nó e versão com comparação de precisão x sem comparação de precisãoNode Type and Lifted versus Non-Lifted
Se o método de implementação não for null :If the implementing method is not null:
Se
left. Digite eright. O tipo pode ser atribuído aos tipos de argumento correspondentes do método de implementação, o nó não é levantado.Ifleft.Type andright.Type are assignable to the corresponding argument types of the implementing method, the node is not lifted. O tipo do nó é o tipo de retorno do método de implementação.The type of the node is the return type of the implementing method.Se as duas condições a seguir forem satisfeitas, o nó será levantado e o tipo do nó será o tipo anulável que corresponde ao tipo de retorno do método de implementação: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:
left. Digite eright. O tipo são ambos os tipos de valor dos quais pelo menos um é anulável e os tipos não anuláveis correspondentes são iguais aos tipos de argumento correspondentes do método de implementação.left.Type andright.Type are both value types of which at least one is nullable and the corresponding non-nullable types are equal to the corresponding argument types of the implementing method.O tipo de retorno do método de implementação é um tipo de valor não anulável.The return type of the implementing method is a non-nullable value type.
Se o método de implementação for null :If the implementing method is null:
Se
left. Digite eright. Os tipos são não anuláveis, o nó não é retirado.Ifleft.Type andright.Type are both non-nullable, the node is not lifted. O tipo do nó é o tipo de resultado do operador de adição predefinido.The type of the node is the result type of the predefined addition operator.Se
left. Digite eright. Os tipos são anuláveis, o nó é levantado.Ifleft.Type andright.Type are both nullable, the node is lifted. O tipo do nó é o tipo anulável que corresponde ao tipo de resultado do operador de adição predefinido.The type of the node is the nullable type that corresponds to the result type of the predefined addition operator.