jhewlett / ValueObject

A micro library for easily creating C# classes with value semantics. No need to override Equals, GetHashCode, et all.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SonarQube warning: Classes implementing "IEquatable<T>" should be sealed

attiqeurrehman opened this issue · comments

Hi,

SonarQube is giving out the warning with the following explanation:

When a class implements the IEquatable interface, it enters a contract that states, "I know how to compare two instances of type T or any type derived from T for equality.". However, if that class is derived, it is improbable that the base class will know how to make a meaningful comparison. Therefore that implicit contract is now broken.

Alternatively, IEqualityComparer provides a safer interface and is used by collections or Equals could be made virtual.

This rule raises an issue when an unsealed, public, or protected class implements IEquitable and the Equals are neither virtual nor abstract

I am looking forward to hearing your thoughts on it.

Thanks