ReSharper sugiere que se cambie la siguiente a partir de:C# Tipo Comparación: Type.Equals vs == operador
Type foo = typeof(Foo);
Type bar = typeof(Bar);
if(foo.Equals(bar)) { ... }
Para:
if(foo == bar) { ... }
== operador
// Summary:
// Indicates whether two System.Type objects are equal.
//
// Parameters:
// left:
// The first object to compare.
//
// right:
// The second object to compare.
//
// Returns:
// true if left is equal to right; otherwise, false.
public static bool operator ==(Type left, Type right);
Igual (Tipo o)
// Summary:
// Determines if the underlying system type of the current System.Type is the
// same as the underlying system type of the specified System.Type.
//
// Parameters:
// o:
// The System.Type whose underlying system type is to be compared with the underlying
// system type of the current System.Type.
//
// Returns:
// true if the underlying system type of o is the same as the underlying system
// type of the current System.Type; otherwise, false.
public virtual bool Equals(Type o);
Pregunta
¿Por qué operator ==
recomendar más Equals(Type o)
al comparar los tipos?
R # típicamente sugerirá algo y dar una razón válida; en este caso, si son funcionalmente equivalentes, tengo dudas de que la sugerencia sea legibilidad, que es subjetiva. Me pregunto si hay otra razón por la que se sugiera. –
@MetroSmurf - R # a menudo sugiere cosas en aras de la legibilidad (reduciendo la anidación en las declaraciones if, por ejemplo). –
Probablemente esa sea la razón prevista, pero como los dos no son funcionalmente equivalentes en este caso, ¿entonces seguramente esto es un error en Resharper? –