GU0020

November 24, 2021 ยท View on GitHub

Sort properties

TopicValue
IdGU0020
SeverityHidden
EnabledTrue
CategoryGu.Analyzers.Correctness
CodeGU0020SortProperties

Description

Sort properties by StyleCop rules then by mutability.

Order:

  1. get-only
  2. Expression body.
  3. private set;, protected set, internal set, public set.

Motivation

To make it easier to keep an eye on state if any.

How to fix violations

Sort the properties.

Configure severity

Via ruleset file.

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

Via #pragma directive.

#pragma warning disable GU0020 // Sort properties
Code violating the rule here
#pragma warning restore GU0020 // Sort properties

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

#pragma warning disable GU0020 // Sort properties

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 
    "GU0020:Sort properties", 
    Justification = "Reason...")]