-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OptionsValidator source-gen shouldn't cover static and const members #88150
Comments
Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations Issue DetailsDescriptionRecently added OptionsValidator (issue #85475 and PR #87587) considers all members of a 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 behaviorA warning is emitted for all three members, no Actual behaviorThe generator produces the next code which won't compile: Regression?No response Known WorkaroundsNo response Configuration.NET SDK 8.0.100-preview.7.23327.3 Other informationNo response
|
cc @tarekgh |
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsDescriptionRecently added OptionsValidator (issue #85475 and PR #87587) considers all members of a 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 behaviorA warning is emitted for all three members, no Actual behaviorThe generator produces the next code which won't compile: Regression?No response Known WorkaroundsNo response Configuration.NET SDK 8.0.100-preview.7.23327.3 Other informationNo response
|
Description
Recently added OptionsValidator (issue #85475 and PR #87587) considers all members of a
TOption
for validation, however we shouldn't validatestatic
ones. Additionally,const
fields should be ignored or a warning should be emitted if such members are annotated with data validation attributes (inherited fromValidationAttribute
).Reproduction Steps
Expected behavior
A warning is emitted for all three members, no
static
orconst
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
The text was updated successfully, but these errors were encountered: