Repository navigation
Use the invariant culture for small and unsigned integer literals in CSharpHelper - #39319
Merged
AndriySvyryd merged 1 commit intoOct 21, 2026
Conversation
…CSharpHelper Literal(int) and Literal(long) format with the invariant culture, but the sbyte/short/byte/ushort/uint/ulong overloads concatenated the value directly, which uses the current culture. In cultures whose negative sign is not ASCII (e.g. sv-SE, nb-NO, fi-FI use U+2212) negative sbyte/short values - such as HasDefaultValue((short)-1), seed data, or unnamed sbyte/short enum values - were generated as "(short)−1", which does not compile in the generated snapshot, migration or scaffolded code.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes address culture-dependent literal generation and include targeted regression coverage.
No open issues 🎉
What changed in this PR
This pull request updates CSharpHelper to generate culture-independent literals for small and unsigned integer types, preventing invalid generated C# under cultures with non-ASCII negative signs.
Changes:
- Applies
CultureInfo.InvariantCulturetobyte,sbyte,short,ushort,uint, andulongliteral formatting. - Adds Swedish-culture regression coverage for negative integer and unnamed enum literals.
| File | Description |
|---|---|
test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs |
Verifies generated literals remain valid under sv-SE, including negative values and enums. |
src/EFCore.Design/Design/Internal/CSharpHelper.cs |
Applies invariant-culture formatting to the affected integer literal overloads. |
Review effort: Lite
AndriySvyryd
approved these changes
Oct 21, 2026
Member
|
Thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Literal(int) and Literal(long) format with the invariant culture, but the sbyte/short/byte/ushort/uint/ulong overloads concatenated the value directly, which uses the current culture. In cultures whose negative sign is not ASCII (e.g. sv-SE, nb-NO, fi-FI use U+2212) negative sbyte/short values - such as HasDefaultValue((short)-1), seed data, or unnamed sbyte/short enum values - were generated as "(short)−1", which does not compile in the generated snapshot, migration or scaffolded code.