Skip to content

Parse dynamic schema values with the reader's culture - #296

Open
menes97 wants to merge 1 commit into
MarkPflug:mainfrom
menes97:fix/dynamic-accessor-culture
Open

menes97 wants to merge 1 commit into
MarkPflug:mainfrom
menes97:fix/dynamic-accessor-culture

Conversation

@menes97

@menes97 menes97 commented Nov 17, 2026

Copy link
Copy Markdown

With CsvSchema.Dynamic, DynamicAccessor.GetValue parsed each field with int/decimal/double/DateTime/TimeSpan.TryParse(str, out ...), which use the current culture (there was a //TODO: culture there). The other accessors and GetDouble/GetDecimal/... use CsvDataReaderOptions.Culture, which defaults to InvariantCulture. So on a machine whose culture uses . as the group separator (de-DE, tr-TR, ...), the dynamic reader returned 124m for 12.4, and CsvDataReaderOptions.Culture had no effect on dynamic values.

This passes the reader's culture to those TryParse calls, with the same NumberStyles/DateTimeStyles the culture-less overloads use (Integer, Number, Float | AllowThousands, None), so the accepted formats don't change. The reader gets an internal Culture property for the accessor.

Test: CsvDataReaderTests.DynamicSchemaUsesReaderCulture sets the current culture to de-DE and checks that 12.4 and 1.5e3 are read as 12.4m and 1500d with the default options, and that 12,4 is read as 12.4m with Culture = de-DE. It fails on master (Actual: 124) and passes with this change. On this machine (tr-TR) the existing DynamicSchema and DynamicReader tests also failed on master for the same reason and pass now.

What I ran (Windows, tr-TR): built Sylvan.Data.Csv for all target frameworks, dotnet test source/Sylvan.Data.Csv.Tests -f net8.0: 237 passed, 8 skipped, 0 failed.

Written with Claude Code (AI); I reviewed the change and ran the tests above.

🤖 Generated with Claude Code

DynamicAccessor (CsvSchema.Dynamic) parsed numbers, dates and time
spans with the current culture instead of CsvDataReaderOptions.Culture
(InvariantCulture by default). On a machine whose culture uses "." as
the group separator (de-DE, tr-TR), "12.4" was read as 124.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant