Expression.Equal Método

Definição

Cria um BinaryExpression que representa uma comparação de igualdade.Creates a BinaryExpression that represents an equality comparison.

Sobrecargas

Equal(Expression, Expression)

Cria um BinaryExpression que representa uma comparação de igualdade.Creates a BinaryExpression that represents an equality comparison.

Equal(Expression, Expression, Boolean, MethodInfo)

Cria um BinaryExpression que representa uma comparação de igualdade.Creates a BinaryExpression that represents an equality comparison. O método de implementação pode ser especificado.The implementing method can be specified.

Equal(Expression, Expression)

Cria um BinaryExpression que representa uma comparação de igualdade.Creates a BinaryExpression that represents an equality comparison.

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

Parâmetros

left
Expression

Um Expression para definir a propriedade Left igual a ele.An Expression to set the Left property equal to.

right
Expression

Um Expression para definir a propriedade Right igual a ele.An Expression to set the Right property equal to.

Retornos

BinaryExpression

Um BinaryExpression que tem a propriedade NodeType igual a Equal e as propriedades Left e Right definidas com os valores especificados.A BinaryExpression that has the NodeType property equal to Equal 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 igualdade não está definido para left.Type e right.Type.The equality 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 verifica se os valores de seus dois argumentos são iguais.The following code example shows how to create an expression that checks whether the values of its two arguments are equal.

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

// This expression compares the values of its two arguments.
// Both arguments need to be of the same type.
Expression equalExpr = Expression.Equal(
    Expression.Constant(42),
    Expression.Constant(45)
);

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

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

// This code example produces the following output:
//
// (42 == 45)
// False
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' This expression compares the values of its two arguments.
' Both arguments must be of the same type.
Dim equalExpr As Expression = Expression.Equal(
    Expression.Constant(42),
    Expression.Constant(45)
)

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

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

' This code example produces the following output:
'
' (42 == 45)
' False

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, a IsLifted propriedade será true .If the node is lifted, the IsLifted property is true. Caso contrário, será false.Otherwise, it is false. A propriedade IsLiftedToNull sempre é false.The IsLiftedToNull property is always false. 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 a Type propriedade de left ou right representar um tipo definido pelo usuário que sobrecarrega o operador de igualdade, o MethodInfo que representa esse método é o método de implementação.If the Type property of either left or right represents a user-defined type that overloads the equality operator, the MethodInfo that represents that method is the implementing method.

  • Caso contrário, o método de implementação é null .Otherwise, the implementing method is null.

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 e right . O tipo pode ser atribuído aos tipos de argumento correspondentes do método de implementação, o nó não é levantado.If left.Type and right.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á Boolean :If the following two conditions are satisfied, the node is lifted and the type of the node is Boolean:

    • left. Digite e right . 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 and right.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 é Boolean .The return type of the implementing method is Boolean.

Se o método de implementação for null :If the implementing method is null:

  • Se left . Digite e right . Os tipos são não anuláveis, o nó não é retirado.If left.Type and right.Type are both non-nullable, the node is not lifted. O tipo do nó é Boolean .The type of the node is Boolean.

  • Se left . Digite e right . Os tipos são anuláveis, o nó é levantado.If left.Type and right.Type are both nullable, the node is lifted. O tipo do nó é Boolean .The type of the node is Boolean.

Aplica-se a

Equal(Expression, Expression, Boolean, MethodInfo)

Cria um BinaryExpression que representa uma comparação de igualdade.Creates a BinaryExpression that represents an equality comparison. O método de implementação pode ser especificado.The implementing method can be specified.

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

Parâmetros

left
Expression

Um Expression para definir a propriedade Left igual a ele.An Expression to set the Left property equal to.

right
Expression

Um Expression para definir a propriedade Right igual a ele.An Expression to set the Right property equal to.

liftToNull
Boolean

true para definir IsLiftedToNull como true; false para definir IsLiftedToNull como false.true to set IsLiftedToNull to true; false to set IsLiftedToNull to false.

method
MethodInfo

Um MethodInfo para definir a propriedade Method igual a ele.A MethodInfo to set the Method property equal to.

Retornos

BinaryExpression

Um BinaryExpression que tem a propriedade NodeType igual a Equal e as propriedades Left, Right, IsLiftedToNull e Method definidas com os valores especificados.A BinaryExpression that has the NodeType property equal to Equal and the Left, Right, IsLiftedToNull, 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 igualdade não está definido para left.Type e right.Type.method is null and the equality 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, a IsLifted propriedade será true e a IsLiftedToNull propriedade será igual a liftToNull .If the node is lifted, the IsLifted property is true and the IsLiftedToNull property is equal to liftToNull. Caso contrário, eles são ambos false .Otherwise, they are both false. 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 method não for null e representar um método que não seja void static ( Shared no Visual Basic) que usa dois argumentos, ele será o método de implementação.If method is not null and it represents a non-void, static (Shared in Visual Basic) method that takes two arguments, it is the implementing method.

  • Caso contrário, se a Type propriedade de left ou right representar um tipo definido pelo usuário que sobrecarrega o operador de igualdade, o MethodInfo que representa esse método é o método de implementação.Otherwise, if the Type property of either left or right represents a user-defined type that overloads the equality operator, the MethodInfo that represents that method is the implementing method.

  • Caso contrário, o método de implementação é null .Otherwise, the implementing method is null.

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 e right . O tipo pode ser atribuído aos tipos de argumento correspondentes do método de implementação, o nó não é levantado.If left.Type and right.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; Além disso, o tipo do nó é anulável Boolean se liftToNull for true ou Boolean se liftToNull for false :If the following two conditions are satisfied, the node is lifted; also, the type of the node is nullable Boolean if liftToNull is true or Boolean if liftToNull is false:

    • left. Digite e right . 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 and right.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 é Boolean .The return type of the implementing method is Boolean.

Se o método de implementação for null :If the implementing method is null:

  • Se left . Digite e right . Os tipos são não anuláveis, o nó não é retirado.If left.Type and right.Type are both non-nullable, the node is not lifted. O tipo do nó é Boolean .The type of the node is Boolean.

  • Se left . Digite e right . Os tipos são anuláveis, o nó é levantado.If left.Type and right.Type are both nullable, the node is lifted. O tipo do nó é anulável Boolean se liftToNull for true ou Boolean se liftToNull for false .The type of the node is nullable Boolean if liftToNull is true or Boolean if liftToNull is false.

Aplica-se a