VALFY01: Type is not compatible with Valuify
November 23, 2024 ยท View on GitHub
| Type Name | VALFY01_AttributeAnalyzer |
| Diagnostic Id | VALFY01 |
| Category | Usage |
| Severity | Warning |
| Is Enabled By Default | Yes |
Cause
A type declaration upon which the Valuify attribute is placed is not a class.
Rule Description
A violation of this rule occurs when the Valuify attribute is placed on a type declaration that is not a class. This occurs most commonly when placed upon a record declaration.
For example:
[Valuify]
public partial record Example(int Value);
How to Fix Violations
To fix a violation of this rule, determine if the declaration type is correct for the intended usage. If the type is correct, remove the Valuify attribute from the declaration, otherwise change the declaration for the type to class.
For example:
[Valuify]
public partial class Example
{
public int Value { get; set; }
}
or alternatively:
public record Example(int Value);
How to Suppress Violations
It is not recommended to suppress the rule. Instead, it is suggested that the usage of the Valuify attribute be reevaluated.
If suppression is desired, one of the following approaches can be used:
#pragma warning disable VALFY01 // Type is not compatible with Valuify
[Valuify]
public partial record Example(int Value);
#pragma warning restore VALFY01 // Type is not compatible with Valuify
or alternatively:
[Valuify]
[SuppressMessage("Design", "VALFY01:Type is not compatible with Valuify", Justification = "Explanation for suppression")]
public partial record Example(int Value);
How to Disable VALFY01
It is not recommended to disable the rule, as this may result in some confusion if the expected equality behavior is not observed.
# Disable VALFY01: Type is not compatible with Valuify
[*.cs]
dotnet_diagnostic.VALFY01.severity = none