Support _ prefix in VersionByNamespaceConvention#1171
Support _ prefix in VersionByNamespaceConvention#1171xavierjohn wants to merge 3 commits intodotnet:mainfrom
Conversation
- Change .NET version in Dockerfile to 10.0 - Upgrade actions/checkout and actions/setup-dotnet to v4 in CodeQL workflow - Enable organizing imports on format in VSCode settings
…te tests accordingly
…ments for versioning
| if ( ch == '_' ) | ||
| { | ||
| // '_' prefix requires the next character to be a digit; | ||
| // otherwise, it's just a regular identifier | ||
| if ( identifier.Length < 2 || !char.IsDigit( identifier[1] ) ) | ||
| { | ||
| apiVersion = default; | ||
| return false; | ||
| } | ||
| } |
Check notice
Code scanning / CodeQL
Nested 'if' statements can be combined Note
There was a problem hiding this comment.
It definitely shouldn't be nested, but I'm not even sure it's necessary for this to exist
commonsensesoftware
left a comment
There was a problem hiding this comment.
This PR contains additional commits that are out of scope of the intended changes.
| return false; | ||
| } | ||
|
|
||
| if ( ch == '_' ) |
There was a problem hiding this comment.
This entire branch of logic doesn't make sense nor is there a test for this use case. What is this scenario? The only possibilities here are _, v, or V, none of which will parse as a valid ApiVersion. If there were only 2 characters, the next letter would always have to be a digit anyway; for example v1. This entire block doesn't appear to be necessary.
| if ( ch == '_' ) | ||
| { | ||
| // '_' prefix requires the next character to be a digit; | ||
| // otherwise, it's just a regular identifier | ||
| if ( identifier.Length < 2 || !char.IsDigit( identifier[1] ) ) | ||
| { | ||
| apiVersion = default; | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
It definitely shouldn't be nested, but I'm not even sure it's necessary for this to exist
Support _ prefix in VersionByNamespaceConvention
Solution:
Accept _ as a valid namespace prefix when followed by a digit. This allows developers to use folder-based namespaces naturally without needing to manually rename them with a v prefix.
Summary of the changes (Less than 80 chars)
Description
When a folder name starts with a number (e.g., 2018_04_01), Visual Studio automatically prepends an underscore to the generated namespace (e.g., _2018_04_01). The NamespaceParser previously only recognized v/V as a valid prefix, so namespaces like Contoso.Api._2018_04_01.Controllers were silently ignored.