Skip to content
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

Fix OptionsValidator source-gen to skip static and const members #88254

Merged
merged 5 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
| __`SYSLIB1211`__ | Options validation generator: Unsupported circular references in model types. |
| __`SYSLIB1212`__ | Options validation generator: Member potentially missing transitive validation. |
| __`SYSLIB1213`__ | Options validation generator: Member potentially missing enumerable validation. |
| __`SYSLIB1214`__ | *_`SYSLIB1214`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
| __`SYSLIB1214`__ | Options validation generator: Can't validate constants, static fields or properties. |
| __`SYSLIB1215`__ | *_`SYSLIB1214`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
| __`SYSLIB1216`__ | *_`SYSLIB1214`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
| __`SYSLIB1217`__ | *_`SYSLIB1214`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
Expand Down
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33815.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{F5A58A9D-3C44-4E3C-A661-1CECA84108D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bcl.AsyncInterfaces", "..\Microsoft.Bcl.AsyncInterfaces\ref\Microsoft.Bcl.AsyncInterfaces.csproj", "{201C7D67-FB1D-4259-9DB4-BF188007F9EA}"
Expand Down Expand Up @@ -165,6 +169,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7028EE0A-D31
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Options.SourceGeneration", "gen\Microsoft.Extensions.Options.SourceGeneration.csproj", "{2B8ED012-22B5-47DD-A879-FD2AFD4C067D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Options.SourceGeneration.Unit.Tests", "tests\SourceGeneration.Unit.Tests\Microsoft.Extensions.Options.SourceGeneration.Unit.Tests.csproj", "{D3B6805B-F10E-4A19-99FC-55506892BC18}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Options.SourceGeneration.Tests", "tests\SourceGenerationTests\Microsoft.Extensions.Options.SourceGeneration.Tests.csproj", "{D7C2C4C7-CF28-4E2B-8749-31D7E6072588}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ComponentModel.Annotations", "..\System.ComponentModel.Annotations\src\System.ComponentModel.Annotations.csproj", "{90548F7B-C673-42C9-BD88-A6E6550ECE1C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -487,90 +499,110 @@ Global
{D7CEC738-5D2D-4FCB-9268-9650EB01BF31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7CEC738-5D2D-4FCB-9268-9650EB01BF31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7CEC738-5D2D-4FCB-9268-9650EB01BF31}.Release|Any CPU.Build.0 = Release|Any CPU
{2B8ED012-22B5-47DD-A879-FD2AFD4C067D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B8ED012-22B5-47DD-A879-FD2AFD4C067D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B8ED012-22B5-47DD-A879-FD2AFD4C067D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B8ED012-22B5-47DD-A879-FD2AFD4C067D}.Release|Any CPU.Build.0 = Release|Any CPU
{D3B6805B-F10E-4A19-99FC-55506892BC18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3B6805B-F10E-4A19-99FC-55506892BC18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3B6805B-F10E-4A19-99FC-55506892BC18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3B6805B-F10E-4A19-99FC-55506892BC18}.Release|Any CPU.Build.0 = Release|Any CPU
{D7C2C4C7-CF28-4E2B-8749-31D7E6072588}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7C2C4C7-CF28-4E2B-8749-31D7E6072588}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7C2C4C7-CF28-4E2B-8749-31D7E6072588}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7C2C4C7-CF28-4E2B-8749-31D7E6072588}.Release|Any CPU.Build.0 = Release|Any CPU
{90548F7B-C673-42C9-BD88-A6E6550ECE1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90548F7B-C673-42C9-BD88-A6E6550ECE1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90548F7B-C673-42C9-BD88-A6E6550ECE1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90548F7B-C673-42C9-BD88-A6E6550ECE1C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F5A58A9D-3C44-4E3C-A661-1CECA84108D9} = {7C1317AA-5F4C-42A4-80F3-856BA5E204AF}
{94CAA850-ABDB-4A1E-B18B-19DA0DE75CFD} = {7C1317AA-5F4C-42A4-80F3-856BA5E204AF}
{201C7D67-FB1D-4259-9DB4-BF188007F9EA} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{F656E22F-D8D2-4C8A-A435-01F821A1EA07} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{5EA013FF-FCA7-4F0B-8EB7-14D8472A0830} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{66E30CB1-ADA8-4000-9CEE-56AF40323D23} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{4F936B46-60DA-4EE3-831A-06DC62E1E155} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{5E90DFC5-7D40-42E4-ADF6-7090015B7211} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{0A7AE964-D27E-44A8-85E1-F7A63EBC1BB6} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{732B0524-C9F0-4752-AD19-5275E863C6E0} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{3975BEAC-6DB6-4CF7-B788-AA5B07D6CAC1} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{B559A43F-4502-4D1B-B8C0-2822DDD8A68C} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{DAD9293C-DB4F-45DE-A1BB-D857B02A0764} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{FFA18D8E-A4A1-4F33-80A6-BD7600E71E91} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{0C4F3A7F-AAED-49A0-B8A3-B63CC83B345D} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{91F2FFBB-8954-4707-A4FF-CF5DF23303E2} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{355E3E07-8273-4660-AE2C-8603A0757C4B} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{195DC43D-4D6C-4631-969F-E89547A84A8D} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{DEE4AA87-8EC4-41EE-A2A3-2DF6F494EAF2} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{692645D6-1F0B-4DB0-85EB-7D4042857B2D} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{D4256787-48E0-473F-8C06-359C1BCFC8AB} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{A29E2B35-847A-4304-BF0F-B0DFDC4384A1} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{0F2B84D6-6C2E-4216-A8CD-DF91908F4194} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{AB7510FB-A8B8-426E-A5FB-D292F1423D5A} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{250B3EA5-65A4-4D62-B0F9-5BAAFE53BD7A} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{05161D6B-0451-43B9-B648-71B7628F2A78} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{6A4A1183-A0CF-4270-8EF9-12018D9DADB9} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{92B8FC4A-A8B5-4799-831D-F82A4BE16B39} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{3C56A02F-4DD8-4253-99E7-34E088A6A9D7} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{6F7512BA-9B15-4395-AE05-C546F0770344} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{36D778AF-5EC3-433F-B03D-EB244DB3C227} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{AA0A7586-364A-4F3B-A9A8-07704D789C23} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{D0932BA0-70BF-4A98-9A30-ED563AB2BFB9} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{F3B41A00-2E87-49F5-9A48-B03E528A6577} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{6AD51705-102E-4E9D-B62E-6BF19025F3A7} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{39EE5D71-77C5-4633-A47F-1062172FD121} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{8A4E7CB4-9983-4B7F-BED9-7A94BAC7CA07} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{333116ED-7874-4ECD-91EC-641B8479F696} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{EFFB59C1-CAF4-4347-B996-4C773E1AFAA8} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{56D37CB2-68A3-42D3-AA0E-416813ABAD8B} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{6AAFBB84-9FF1-4E16-9309-6A0A251EE420} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{9EBA168F-239A-46C4-8614-E1D3DB25DD0E} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{5DBF771C-E3DE-4538-BB8B-33029EDA0BCB} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{47B5D904-4787-49E3-9894-31F8B7BE6755} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{5570AF22-F440-4887-BFC9-CB9B557712D3} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{3E400E69-1699-412B-A202-764A967A6E51} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{CB19F6BB-E51B-4B37-AF0F-63348C7FF48E} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{7F2C68B0-A922-4455-BAF3-335E44DF6BB9} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{E9A3C3E5-78C9-44B3-9C8B-B764DD8DEA08} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{A9E52F82-6B9C-4E07-919B-2B1BFFB21DBB} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{37B75F58-26C3-4BD8-8285-C94F2B00DFD6} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{DA91110F-C553-45E4-93E7-948A93AD09AF} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{CD668E6C-9DD5-456E-A23A-9880A779CA14} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{6AF79D67-4D64-40B4-9276-BCC06B8BAF58} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{02C282B1-23DD-429A-ADC7-345D661557E1} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{3A6E2FA4-B745-4E4B-A82E-98CAD1177E77} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{D0CAEF2C-FB83-4C32-80BD-1F516AD13FAA} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{9BA945E7-0970-4CA2-A54B-F8D9B3E69917} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{94CAA850-ABDB-4A1E-B18B-19DA0DE75CFD} = {7C1317AA-5F4C-42A4-80F3-856BA5E204AF}
{36C471D8-1D7A-4C81-8B05-2EED0984FBB4} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{AAB5D437-EFB2-4BAC-BA0F-7323BA691B89} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{3CE1FDFB-3BFD-463E-AC82-4E5302F0AB2F} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{6AE427EF-C018-4075-A4C8-BF3831C5F88C} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{6A1A3AFF-C018-498A-80A0-532396132AD5} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{11773B90-8DAC-4B51-A4B6-7C64FD6942BD} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{990280EA-CDBD-480A-8224-DBCBA8B6D6DB} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{B0249028-C048-40B8-B102-BCE7928965C3} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{9F1389B4-A9A5-422F-89F5-A2D431292F0C} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{6E2398EA-A64A-4493-A79B-63D2F072A690} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{F656E22F-D8D2-4C8A-A435-01F821A1EA07} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{66E30CB1-ADA8-4000-9CEE-56AF40323D23} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{0A7AE964-D27E-44A8-85E1-F7A63EBC1BB6} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{3975BEAC-6DB6-4CF7-B788-AA5B07D6CAC1} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{DAD9293C-DB4F-45DE-A1BB-D857B02A0764} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{0C4F3A7F-AAED-49A0-B8A3-B63CC83B345D} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{355E3E07-8273-4660-AE2C-8603A0757C4B} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{DEE4AA87-8EC4-41EE-A2A3-2DF6F494EAF2} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{D4256787-48E0-473F-8C06-359C1BCFC8AB} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{0F2B84D6-6C2E-4216-A8CD-DF91908F4194} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{250B3EA5-65A4-4D62-B0F9-5BAAFE53BD7A} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{6A4A1183-A0CF-4270-8EF9-12018D9DADB9} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{3C56A02F-4DD8-4253-99E7-34E088A6A9D7} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{36D778AF-5EC3-433F-B03D-EB244DB3C227} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{D0932BA0-70BF-4A98-9A30-ED563AB2BFB9} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{6AD51705-102E-4E9D-B62E-6BF19025F3A7} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{56D37CB2-68A3-42D3-AA0E-416813ABAD8B} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{9EBA168F-239A-46C4-8614-E1D3DB25DD0E} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{47B5D904-4787-49E3-9894-31F8B7BE6755} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{3E400E69-1699-412B-A202-764A967A6E51} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{7F2C68B0-A922-4455-BAF3-335E44DF6BB9} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{A9E52F82-6B9C-4E07-919B-2B1BFFB21DBB} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{DA91110F-C553-45E4-93E7-948A93AD09AF} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{6AF79D67-4D64-40B4-9276-BCC06B8BAF58} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{3A6E2FA4-B745-4E4B-A82E-98CAD1177E77} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{9BA945E7-0970-4CA2-A54B-F8D9B3E69917} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{AAB5D437-EFB2-4BAC-BA0F-7323BA691B89} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{429C9D71-4BBD-489D-9C86-EC240F652008} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{11773B90-8DAC-4B51-A4B6-7C64FD6942BD} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{99007CDD-4840-4B94-8A8A-FECF72BCEE3F} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{9175023F-6982-45CD-B360-C4FC1E145B25} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{59D31D62-3BF9-4F4A-9FF7-3A61F297F714} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{D7CEC738-5D2D-4FCB-9268-9650EB01BF31} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{4F936B46-60DA-4EE3-831A-06DC62E1E155} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{39EE5D71-77C5-4633-A47F-1062172FD121} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{8A4E7CB4-9983-4B7F-BED9-7A94BAC7CA07} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{333116ED-7874-4ECD-91EC-641B8479F696} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{990280EA-CDBD-480A-8224-DBCBA8B6D6DB} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{62065BFE-5477-44DD-A328-582B0F050EC3} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{02425B61-8D98-4F4A-88AE-F77D4837DF9E} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{E0460280-2F49-474C-862D-1787D9244CC8} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{B0249028-C048-40B8-B102-BCE7928965C3} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{9F1389B4-A9A5-422F-89F5-A2D431292F0C} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{59D31D62-3BF9-4F4A-9FF7-3A61F297F714} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{B5F25A78-B7FB-460B-9B71-BE82D22923FD} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{E06CE29E-15EB-4C0E-97B7-4367FFEDD98D} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{9021FD06-E11E-42DE-87EF-A1040BA5DB56} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{6E2398EA-A64A-4493-A79B-63D2F072A690} = {72A090A3-FE14-4F4E-B266-EFFB5C736462}
{D7CEC738-5D2D-4FCB-9268-9650EB01BF31} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
{2B8ED012-22B5-47DD-A879-FD2AFD4C067D} = {C25891DB-FBAC-4B92-9BB9-A8181B5A0EF1}
{D3B6805B-F10E-4A19-99FC-55506892BC18} = {7C1317AA-5F4C-42A4-80F3-856BA5E204AF}
{D7C2C4C7-CF28-4E2B-8749-31D7E6072588} = {7C1317AA-5F4C-42A4-80F3-856BA5E204AF}
{90548F7B-C673-42C9-BD88-A6E6550ECE1C} = {7028EE0A-D314-4F48-91CA-51A1633BC3F4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FE89CDC6-6313-439C-85D7-A81D5DF593E9}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,12 @@ internal sealed class DiagDescriptors : DiagDescriptorsBase
messageFormat: SR.PotentiallyMissingEnumerableValidationMessage,
category: Category,
defaultSeverity: DiagnosticSeverity.Warning);

public static DiagnosticDescriptor CantValidateStaticOrConstMember { get; } = Make(
id: "SYSLIB1214",
title: SR.CantValidateStaticOrConstMemberTitle,
messageFormat: SR.CantValidateStaticOrConstMemberMessage,
category: Category,
defaultSeverity: DiagnosticSeverity.Warning);
}
}
18 changes: 16 additions & 2 deletions src/libraries/Microsoft.Extensions.Options/gen/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,20 @@ private List<ValidatedMember> GetMembersToValidate(ITypeSymbol modelType, bool s
}
}

bool validationAttributeIsApplied = validationAttrs.Count > 0 || transValidatorTypeName is not null || enumerationValidatorTypeName is not null;

if (member.IsStatic)
{
// generate an error if the member is static and has a validation attribute applied
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// generate an error if the member is static and has a validation attribute applied

Is it the correct thing to generate error and not just ignoring the statics?

Copy link
Contributor Author

@xakep139 xakep139 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change this to warning, or completely ignore these cases. But it's better to notify a user about incorrect usage and that these members won't be validated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good if we check what is the runtime behavior when having the validation attribute on the statics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a validation framework like ASP.NET MVC or ASP.NET Core, the RequiredAttribute alone would not automatically trigger validation for static properties. These frameworks primarily focus on validating instance properties of classes that are involved in HTTP request processing.

Considering that, I would say making it as warning will make sense.

@jeffhandley @geeknoid what do you think about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out it was a warning already (bad copy-paste). Added an additional assertion in tests to ensure that

if (validationAttributeIsApplied)
{
Diag(DiagDescriptors.CantValidateStaticOrConstMember, member.GetLocation(), member.Name);
}

// don't validate the member in any case
return null;
}

// generate a warning if the field/property seems like it should be transitively validated
if (transValidatorTypeName == null && speculate && memberType.SpecialType == SpecialType.None)
{
Expand All @@ -462,7 +476,7 @@ private List<ValidatedMember> GetMembersToValidate(ITypeSymbol modelType, bool s
}

// generate a warning if the field/property seems like it should be enumerated
if (enumerationValidatorTypeName == null && speculate)
if (enumerationValidatorTypeName == null && speculate && memberType.SpecialType != SpecialType.System_String)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't check string internals anymore

{
var enumeratedType = GetEnumeratedType(memberType);
if (enumeratedType is not null)
Expand All @@ -478,7 +492,7 @@ private List<ValidatedMember> GetMembersToValidate(ITypeSymbol modelType, bool s
}
}

if (validationAttrs.Count > 0 || transValidatorTypeName is not null || enumerationValidatorTypeName is not null)
if (validationAttributeIsApplied)
{
return new(
member.Name,
Expand Down
Loading
Loading