Write values in the invariant culture when they are parsed with it [patch] - #102
Merged
Merged
Conversation
…atch] A conversion method that takes an IFormatProvider is called with the invariant culture, but Write and WriteAsPropertyName formatted with plain ToString(), which uses the current culture. Under a ',' decimal culture, Complex(1.5, 2.5) came back as <15; 25> with no error. Such values are now written through IFormattable.ToString(null, InvariantCulture); types parsed with a single-string method keep their own ToString(). Fixes #97 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B9RFdjRB3ff72GWre48NPs
|
This was referenced Sep 27, 2026
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.



Fixes #97
What changed
Since #96, a conversion method that takes an
IFormatProvideris called withCultureInfo.InvariantCulture.WriteandWriteAsPropertyNamestill formatted with plainToString(), which uses the current culture. Under a culture with,as the decimal separator,Complex(1.5, 2.5)was written as<1,5; 2,5>and read back as<15; 25>, and no error was raised.ReadsWithInvariantCulture, which is true when the selected conversion method has anIFormatProviderparameter (the same condition under whichBuildArgumentspasses the invariant culture).FormatValue. When that flag is set and the value isIFormattable, it writesToString(null, CultureInfo.InvariantCulture). Otherwise it keepsToString().WriteandWriteAsPropertyNameboth useFormatValue.This follows the issue's "at minimum" option on purpose. A type read through a single-string
Parseparses with the current culture, so itsToString()is left alone. Changing it would break that type's round trip instead.Tests
New
CultureRoundTripTests, run under a culture with,as the decimal separator:Complexround-trips unchangedParse(string, IFormatProvider)type round-trips as a property and as a dictionary keyParse(string)keeps writing"1,5"and round-tripsThe test project runs with
System.Globalization.Invariant: true(set by ktsu.Sdk), sode-DEcan't be created there. The tests use a writable clone of the invariant culture with de-DE's decimal and group separators instead. That exercises the same formatting path on every CI runner and doesn't change the globalization mode for the whole test project.Without the fix, the three round-trip cases fail and 102 other tests pass. With it, all 105 tests pass. The library builds cleanly for all its target frameworks.
This PR is independent of #100 and #101. All three start from
main.🤖 Generated with Claude Code
https://claude.ai/code/session_01B9RFdjRB3ff72GWre48NPs
Generated by Claude Code