docs2/site/docs/analyzers/gql019.md
| Value | |
|---|---|
| Rule ID | GQL019 |
| Category | Usage |
| Default severity | Error |
| Enabled by default | Yes |
| Code fix provided | No |
| Introduced in | v8.1 |
This rule is triggered when parser method specified by the Validator attribute
has invalid signature.
The method specified by the Validator attribute must be:
staticvoidobjectAdditionally, if the specified method is defined in a different class from where
the attribute is applied, the method must be declared as public.
Fix the method signature to match the required pattern.
public class TestClass
{
[Validator(nameof(Validate))]
public string Hello1 { get; set; }
[Validator(typeof(Validators), nameof(Validators.ValidateValue))]
public string Hello2 { get; set; }
// must be static
private void Validate(object value) => _ = Convert.ToInt32(value);
}
public class Validators
{
// must be public
internal static void ValidateValue(object value) => _ = Convert.ToInt32(value);
}
Fix the attribute argument to match the method name
public class TestClass
{
[Validator(nameof(Validate))]
public string Hello1 { get; set; }
[Validator(typeof(Validators), nameof(Validators.ValidateValue))]
public string Hello2 { get; set; }
// must be static
private static void Validate(object value) => _ = Convert.ToInt32(value);
}
public class Validators
{
public static void ValidateValue(object value) => _ = Convert.ToInt32(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 GQL019
// The code that's violating the rule is on this line.
#pragma warning restore GQL019
To disable the rule for a file, folder, or project, set its severity to none
in the
configuration file.
[*.cs]
dotnet_diagnostic.GQL019.severity = none
For more information, see How to suppress code analysis warnings.
GQL017: Could not find method
GQL018: Parser method must be valid
GQL020: ValidateArguments method must be valid