docs2/site/docs/analyzers/gql017.md
| Value | |
|---|---|
| Rule ID | GQL017 |
| Category | Usage |
| Default severity | Error |
| Enabled by default | Yes |
| Code fix provided | No |
| Introduced in | v8.1 |
This rule is triggered when one of the following attributes specify a method name that doesn't exist on the specified type:
The Validator, Parser, and ValidateArguments attributes serve as extension
points when defining the schema using a type-first approach. These attributes
enable method selection by specifying the type and method name. This diagnostic
is triggered when the method with the specified name cannot be found on the
designated type.
Create the method with specified name, fix the attribute arguments or rename the method to match the arguments.
public class TestClass
{
[Parser(typeof(Parsers), "Parse")]
public string Hello { get; set; }
}
public static class Parsers
{
public static object ParseValue(object value) => value;
}
Fix the attribute argument to match the method name
public class TestClass
{
[Parser(typeof(Parsers), "ParseValue")]
public string Hello { get; set; }
}
public static class Parsers
{
public static object ParseValue(object value) => value;
}
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 GQL017
// The code that's violating the rule is on this line.
#pragma warning restore GQL017
To disable the rule for a file, folder, or project, set its severity to none
in the
configuration file.
[*.cs]
dotnet_diagnostic.GQL017.severity = none
For more information, see How to suppress code analysis warnings.
GQL018: Parser method must be valid
GQL019: Validator method must be valid
GQL020: ValidateArguments method must be valid