Skip to content

Lower-case generated constructor parameter names with the invariant culture - #1032

Merged
DocSvartz merged 1 commit into
MapsterMapper:developmentfrom
menes97:fix/translator-invariant-ctor-params
Nov 18, 2026
Merged

DocSvartz merged 1 commit into
MapsterMapper:developmentfrom
menes97:fix/translator-invariant-ctor-params

Conversation

@menes97

@menes97 menes97 commented Nov 16, 2026

Copy link
Copy Markdown

ExpressionTranslator writes a constructor for read-only properties (and the positional parameters of a record) and names each parameter char.ToLower(parameter.Name[0]) + parameter.Name.Substring(1). char.ToLower uses the current culture, and in the Turkish and Azerbaijani cultures 'I' lower-cases to 'ı' (dotless i). So on such a machine a property Id gives

public MockClass(int ıd)
{
    this.Id = ıd;
}

It still compiles, but the generated API (parameter names, named arguments) depends on the culture of the machine that runs Mapster.Tool. Both places now use char.ToLowerInvariant; output for other cultures is unchanged.

Test: DebugInfoInjectorTest.TestConstructorParameterNamesDoNotDependOnCurrentCulture generates a class with a read-only Id under tr-TR (restoring the culture afterwards) and checks for public MockClass(int id) and this.Id = id;. It fails without the change (it produced int ıd). ExpressionDebugger.Tests: 40 passed on net6.0, net7.0 and net48 (run with DOTNET_ROLL_FORWARD=Major on .NET 8+ here).

The change and test were written with Claude Code (AI assistance); I reviewed and ran them.

🤖 Generated with Claude Code

…ulture

ExpressionTranslator derived a constructor parameter name from the property
name with char.ToLower, which uses the current culture. On a machine with
the Turkish or Azerbaijani culture a property "Id" produced the parameter
"ıd" (dotless i), so code generated by Mapster.Tool depended on the build
machine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DocSvartz
DocSvartz merged commit e20c5b3 into MapsterMapper:development Nov 18, 2026
1 of 2 checks passed
@DocSvartz

DocSvartz commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

@menes97 Thanks!
This fix will be included in the next pre-release version.

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