Skip to content

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

@attiqeurrehman

Description

@attiqeurrehman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions