GU0074

November 24, 2021 ยท View on GitHub

Prefer pattern

TopicValue
IdGU0074
SeverityHidden
EnabledTrue
CategoryGu.Analyzers.Correctness
CodeBinaryExpressionAnalyzer

Description

Prefer C#8 pattern syntax. Convenience fix for refactoring to pattern syntax. Supports a few simple common cases like:

and

when

The analyzer is default hidden meaning it will work as a refactoring.

Motivation

Pattern syntax is nicer many times. Avoids putting locals in scope.

How to fix violations

Use the fix.

Configure severity

Via ruleset file.

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

Via #pragma directive.

#pragma warning disable GU0074 // Prefer pattern
Code violating the rule here
#pragma warning restore GU0074 // Prefer pattern

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

#pragma warning disable GU0074 // Prefer pattern

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 
    "GU0074:Prefer pattern", 
    Justification = "Reason...")]