Topic | Value |
---|---|
Id | GU0003 |
Severity | Hidden |
Enabled | True |
Category | Gu.Analyzers.Correctness |
Code | ConstructorAnalyzer |
Name the constructor parameters to match the assigned member. This is useful when serializing using NewtonSoft.Json and when using named arguments.
In the below code the parameter named notMatching
should be named a
to match the property it sets.
public class Foo
{
public Foo(int notMatching, int b, int c, int d)
{
this.A = notMatching;
this.B = b;
this.C = c;
this.D = d;
}
public int A { get; }
public int B { get; }
public int C { get; }
public int D { get; }
}
public class Foo
{
public Foo(int a, int b, int c, int d)
{
this.A = a;
this.B = b;
this.C = c;
this.D = d;
}
public int A { get; }
public int B { get; }
public int C { get; }
public int D { get; }
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable GU0003 // Name the parameter to match the assigned member
Code violating the rule here
#pragma warning restore GU0003 // Name the parameter to match the assigned member
Or put this at the top of the file to disable all instances.
#pragma warning disable GU0003 // Name the parameter to match the assigned member
[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness",
"GU0003:Name the parameter to match the assigned member",
Justification = "Reason...")]