Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CSV extenstion uses invariant culture #156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stefanedwards
Copy link

Fixes #155

Added support for specifying culture info for csv writer.

Added support for specifying culture info for csv reader and writer.
{
case "invariantculture": return CultureInfo.InvariantCulture;
case "current": return CultureInfo.CurrentCulture;
default: return CultureInfo.GetCultureInfo(this.Culture);
Copy link
Contributor

Choose a reason for hiding this comment

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

Great addition, I know this is an edge case, but it's entirely possible someone specifies an invalid Culture which would cause this line to fail. Can you implement an IValidatableObject that validates the this.Culture property is a valid culture and fail validation if not. There are a couple examples in other extensions you can follow. CultureInfo doesn't have a TryParse, it looks like probably checking against the systems Cultures would be a possible approach: https://stackoverflow.com/a/12345652.

Copy link
Author

Choose a reason for hiding this comment

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

I chose to use a simple Try/Catch on the Validate method to catch invalid cultures. The GetCultureInfo() will still throw an exception when used directly.

@@ -35,9 +36,17 @@ Source supports an optional `Delimiter` parameter (`,` by default) and an option

Sink supports an optional `Delimiter` parameter (`,` by default) and an optional `IncludeHeader` parameter (`true` by default) to add a leading row of column names.

Formatting options, or locale, can be set with an optional `Culture` setting (`"Invariant"` by default).
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be confusing to not have the settings match the CultureInfo properties. InvariantCultureand CurrentCulture. The way the switch is currently implemented "invariantculture" works but "invariant" won't. For consistency, I'd choose either "Invariant"/"Current" or "InvariantCulture"/"CurrentCulture".

Copy link
Author

Choose a reason for hiding this comment

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

The switch case accepts both, but I have specified only InvariantCulture/CurrentCulture in the README file.

- Added `IValidatableObject` to `CsvWriterSettings`.
- Updated Culture to accept both `Invariant`/`Current` and `InvariantCulture`/`CurrentCulture`.
- Specified only the latter in README.
- Added unit testing for `CsvWriterSettings`.
Copy link
Contributor

@philnach philnach left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for adding unit tests as well. @bowencode can you take a look at this PR?

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.

CSV extension strictly uses local culture, not InvariantCulture
2 participants