rspec/rules/S3875/rule.adoc
2022-02-04 16:28:24 +00:00

19 lines
767 B
Plaintext

The use of ``++==++`` to compare two objects is expected to do a reference comparison. That is, it is expected to return ``++true++`` if and only if they are the same object instance. Overloading the operator to do anything else will inevitably lead to the introduction of bugs by callers. On the other hand, overloading it to do exactly that is pointless; that's what ``++==++`` does by default.
== Noncompliant Code Example
[source,text]
----
public static bool operator== (MyType x, MyType y) // Noncompliant
{
----
== Exceptions
* Classes with overloaded ``++operator +++`` or ``++operator -++`` methods are ignored.
* Classes that implement ``++IComparable<T>++`` or ``++IEquatable<T>++`` most probably behave as a value-type objects and so are ignored.