-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Description
Description
Recently added OptionsValidator (issue #85475 and PR #87587) considers all members of a TOption for validation, however we shouldn't validate static ones. Additionally, const fields should be ignored or a warning should be emitted if such members are annotated with data validation attributes (inherited from ValidationAttribute).
Reproduction Steps
[OptionsValidator]
public partial class MyValidator : IValidateOptions<MyOptions>
{
}
public class MyOptions
{
[Required]
public static string? StaticStringField;
[Required]
public static string? StaticStringProperty => "static";
[Required]
public const string? ConstString = null;
}Expected behavior
A warning is emitted for all three members, no static or const members are validated in the generated code.
Actual behavior
The generator produces the next code which won't compile:

Regression?
No response
Known Workarounds
No response
Configuration
.NET SDK 8.0.100-preview.7.23327.3
Other information
No response