Topic | Value |
---|---|
Id | GU0001 |
Severity | Hidden |
Enabled | True |
Category | Gu.Analyzers.Correctness |
Code | ArgumentListAnalyzer |
Name the arguments of calls to methods that have more than 3 arguments and are placed on separate lines.
The warning is shown when the following criteria are met:
- More than 3 arguments.
- Each argument on their own row.
- At least two adjacent arguments are of the same type.
- Not in an expression tree.
Naming the arguments can help in keeping things clear & correct. This comes up most often when calling constructors for immutable types:
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; }
private Foo Create(int a, int b, int c, int d)
{
return new Foo(
a,
b,
c,
d);
}
}
Use the code fix. Or manually Name the parameter to match the assigned member
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; }
private Foo Create(int a, int b, int c, int d)
{
return new Foo(
a: a,
b: b,
c: c,
d: d);
}
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable GU0001 // Name the argument
Code violating the rule here
#pragma warning restore GU0001 // Name the argument
Or put this at the top of the file to disable all instances.
#pragma warning disable GU0001 // Name the argument
[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness",
"GU0001:Name the argument",
Justification = "Reason...")]