GQL016: Require parameterless constructor
Value | |
---|---|
Rule ID | GQL016 |
Category | Usage |
Default severity | Error |
Enabled by default | Yes |
Code fix provided | No |
Introduced in | v8.0 |
Cause
This rule is triggered when a type implementing an interface is required to have a public parameterless constructor but does not have one.
Rule description
Certain APIs provided by the GraphQL.NET library require that types implementing an interface must have a parameterless constructor. This rule ensures compliance by verifying the presence of such a constructor and reporting an error if the type does not meet this requirement.
How to fix violations
Define parameterless constructor on the type or remove all the constructors.
Example of a violation
public class MyComplexityAnalyzer : IFieldComplexityAnalyzer
{
public MyComplexityAnalyzer(ILogger<MyComplexityAnalyzer> logger)
{
}
public FieldComplexityResult Analyze(FieldImpactContext context)
{
return new FieldComplexityResult(10, 1);
}
}
Example of how to fix
Define parameterless constructor on the type or remove all the constructors.
public class MyComplexityAnalyzer : IFieldComplexityAnalyzer
{
public FieldComplexityResult Analyze(FieldImpactContext context)
{
return new FieldComplexityResult(10, 1);
}
}
Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable GQL016
// The code that's violating the rule is on this line.
#pragma warning restore GQL016
To disable the rule for a file, folder, or project, set its severity to none
in the
configuration file.
[*.cs]
dotnet_diagnostic.GQL016.severity = none
For more information, see How to suppress code analysis warnings.