Topic | Value |
---|---|
Id | GU0004 |
Severity | Hidden |
Enabled | True |
Category | Gu.Analyzers.Correctness |
Code | ConstructorAnalyzer |
Assign all readonly members.
In the following code the readonly member B is never assigned.
public class Foo
{
public Foo(int a)
{
this.A = a;
}
public int A { get; }
public int B { get; }
}
Assign a value to B in constructor or in initializer (showing borth in the example below):
public class Foo
{
public Foo(int a)
{
this.A = a;
this.B = 2;
}
public int A { get; }
public int B { get; } = 3;
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable GU0004 // Assign all readonly members
Code violating the rule here
#pragma warning restore GU0004 // Assign all readonly members
Or put this at the top of the file to disable all instances.
#pragma warning disable GU0004 // Assign all readonly members
[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness",
"GU0004:Assign all readonly members",
Justification = "Reason...")]