GU0074
November 24, 2021 ยท View on GitHub
Prefer pattern
| Topic | Value |
|---|---|
| Id | GU0074 |
| Severity | Hidden |
| Enabled | True |
| Category | Gu.Analyzers.Correctness |
| Code | BinaryExpressionAnalyzer |
Description
Prefer C#8 pattern syntax. Convenience fix for refactoring to pattern syntax. Supports a few simple common cases like:


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...")]