GU0013
November 24, 2021 ยท View on GitHub
Throw for correct parameter
| Topic | Value |
|---|---|
| Id | GU0013 |
| Severity | Warning |
| Enabled | True |
| Category | Gu.Analyzers.Correctness |
| Code | ObjectCreationAnalyzer |
Description
Throw for correct parameter.
Motivation
In the below code the wrong name is used.
public Foo(string bar)
{
this.bar = bar ?? throw new ArgumentNullException(nameof(Foo));
}
How to fix violations
Use the code fix to change it to:
public Foo(string bar)
{
this.bar = bar ?? throw new ArgumentNullException(nameof(bar));
}
Configure severity
Via ruleset file.
Configure the severity per project, for more info see MSDN.
Via #pragma directive.
#pragma warning disable GU0013 // Throw for correct parameter
Code violating the rule here
#pragma warning restore GU0013 // Throw for correct parameter
Or put this at the top of the file to disable all instances.
#pragma warning disable GU0013 // Throw for correct parameter
Via attribute [SuppressMessage].
[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness",
"GU0013:Throw for correct parameter",
Justification = "Reason...")]