Skip to content

Use PascalCase for generated C# extensible enum members - #12623

Open
Jorge Rangel (jorgerangel-msft) wants to merge 11 commits into
mainfrom
copilot/ensure-enum-members-naming-guidelines
Open

Jorge Rangel (jorgerangel-msft) wants to merge 11 commits into
mainfrom
copilot/ensure-enum-members-naming-guidelines

Conversation

@jorgerangel-msft

@jorgerangel-msft Jorge Rangel (jorgerangel-msft) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The C# generator can emit extensible enum members in all caps, such as AND and OR. Generated names should follow .NET PascalCase conventions unless the member is marked exact.

  • Naming: Normalize uppercase words before removing separators, so NOT_FOUND becomes NotFound.
  • Compatibility: Preserve exact names, custom names, and previously published names. Fixed enums and serialized values are unchanged.
StringExtensibleEnum.And.ToString(); // "AND"
StringExtensibleEnum.OR.ToString();  // "OR"; the member name was marked exact

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Nov 19, 2026
@jorgerangel-msft Jorge Rangel (jorgerangel-msft) changed the title [WIP] Ensure generated enums members follow Pascal case naming guidelines Use PascalCase for generated C# extensible enum members Nov 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@12623

commit: f1d7fb2

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The URL rewrite can break backward compatibility by dropping published enum members, while numeric-suffixed names such as HTTP2 and UTF8 still bypass casing normalization.

2 open issues
What changed in this PR

Updates the C# generator to use PascalCase for non-exact extensible enum members, addressing #12602 while aiming to preserve existing API names and serialized values.

Changes:

  • Normalizes uppercase words before removing separators, turning NOT_FOUND into NotFound.
  • Integrates normalization with existing enum naming and compatibility handling.
  • Adds tests for uppercase names, acronyms, exact names, and unchanged serialized values.
File Description
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​test/​Providers/​EnumProviders/​EnumProviderTests.cs Adds member-casing and serialized-value assertions.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​Providers/​ExtensibleEnumProvider.cs Enables uppercase normalization for extensible enums.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​Providers/​EnumProvider.cs Integrates optional normalization into member-name generation.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​Extensions/​StringExtensions.cs Adds regex-based uppercase-word normalization.

Review effort: Balanced

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The normalization pattern still leaves two-letter enum members with numeric suffixes, such as VM2 and IO2, all-uppercase and needs a fix with regression coverage while preserving the IPV4/IPV6 exceptions.

1 open issue
2 resolved since last review

Review effort: Balanced

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the extensible-enum casing update.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jorgerangel-msft

Copy link
Copy Markdown
Contributor Author

regen preview Azure/azure-sdk-for-net#65104

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure Generated Enums Members in Extensible Enums Follow Naming Guidelines

3 participants