Resharper sugeruje, że dodaje się zmieniło od:C# Typ Porównanie: Type.Equals vs == operatora
Type foo = typeof(Foo);
Type bar = typeof(Bar);
if(foo.Equals(bar)) { ... }
Do:
if(foo == bar) { ... }
operatora ==
// 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);
Równe (Type 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);
Pytanie
Dlaczego operator ==
być zalecana przez Equals(Type o)
przy porównywaniu typy?
R # zazwyczaj sugerują coś i dostarczyć ważny powód; w tym przypadku, jeśli są funkcjonalnie równoważne, mam wątpliwości, czy sugestia dotyczy czytelności, która jest subiektywna. Zastanawiam się, czy jest inny powód, dla którego jest to sugerowane? –
@MetroSmurf - R # często sugeruje rzeczy ze względu na czytelność (na przykład zmniejszanie zagnieżdżania w instrukcjach if). –
To jest prawdopodobnie zamierzony powód, ale ponieważ nie są one funkcjonalnie równoważne w tym przypadku, to z pewnością jest to błąd w Resharperze? –