Skip to content

Support _ prefix in VersionByNamespaceConvention#1171

Closed
xavierjohn wants to merge 3 commits intodotnet:mainfrom
xavierjohn:dev/xavier/_convention
Closed

Support _ prefix in VersionByNamespaceConvention#1171
xavierjohn wants to merge 3 commits intodotnet:mainfrom
xavierjohn:dev/xavier/_convention

Conversation

@xavierjohn
Copy link
Collaborator

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.

  • [X ] You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

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.

- 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
Comment on lines +181 to +190
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

These 'if' statements can be combined.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It definitely shouldn't be nested, but I'm not even sure it's necessary for this to exist

Copy link
Collaborator

@commonsensesoftware commonsensesoftware left a comment

Choose a reason for hiding this comment

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

This PR contains additional commits that are out of scope of the intended changes.

return false;
}

if ( ch == '_' )
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Comment on lines +181 to +190
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;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It definitely shouldn't be nested, but I'm not even sure it's necessary for this to exist

@xavierjohn xavierjohn closed this by deleting the head repository Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants