Closed ericwood8 closed 1 week ago
Hi @ericwood8,
Thanks for the suggestion. This is not something that the project system controls. Diagnostics for this kind of thing are Roslyn analyzers.
There's a feature request for this on the Roslyn repo here that you can vote on and follow: https://github.com/dotnet/roslyn/issues/10290
You might like to add a comment including some of your suggestions there.
It's also possible that they'd accept a PR if you felt like contributing to that project.
Summary
Add compiler warning about CS file name not matching the class/interface contained within. Maybe wording could be "File Name/Class Name mismatch."?
User Impact
None, except for seeing warning on build.
Which Files?
Skip: 1) CS files with multiple classes 2) non-class & non-interface CS files 3) non-CS files such as *.html
Include: 1) CS files with interface
Implementation
Would delay building/rebuilding but can minimize impact of checking. Maybe cache a integer (0=no known mismatches, 1=known mismatches, 2=unknown state) that there are problems or not. If problems, then keep checking on subsequent compiles. If no problems with file/class name mismatches, then no need to check on subsequent build/rebuilds. If freshly starting VS, then start with unknown state. If load a new solution into VS, then reset the cache to an unknown state.