GU0025

November 24, 2021 ยท View on GitHub

Seal type with overridden equality

TopicValue
IdGU0025
SeverityInfo
EnabledTrue
CategoryGu.Analyzers.Correctness
CodeClassDeclarationAnalyzer

Description

Seal type with overridden equality.

Motivation

If Equals or GetHashCode are overriden it often makes sense to seal the type as subclassing gest messy with equality.

How to fix violations

Use the code fix.

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable GU0025 // Seal type with overridden equality
Code violating the rule here
#pragma warning restore GU0025 // Seal type with overridden equality

Or put this at the top of the file to disable all instances.

#pragma warning disable GU0025 // Seal type with overridden equality

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 
    "GU0025:Seal type with overridden equality", 
    Justification = "Reason...")]