Topic | Value |
---|---|
Id | GU0006 |
Severity | Hidden |
Enabled | True |
Category | Gu.Analyzers.Correctness |
Code | StringLiteralExpressionAnalyzer |
Use nameof.
Using nameof is more refactoring friendly than string literals. In the following snippet nameof is preferable for parameter name.
public class C
{
public void M(object value)
{
if (value is null)
{
throw new ArgumentNullException(""value"");
}
}
}
Use the cod fix or manually change it to:
public class C
{
public void M(object value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
}
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable GU0006 // Use nameof
Code violating the rule here
#pragma warning restore GU0006 // Use nameof
Or put this at the top of the file to disable all instances.
#pragma warning disable GU0006 // Use nameof
[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness",
"GU0006:Use nameof",
Justification = "Reason...")]