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

Add support to change the current CulutureInfo #187

Closed
wants to merge 2 commits into from
Closed

Add support to change the current CulutureInfo #187

wants to merge 2 commits into from

Conversation

smashlines
Copy link

When the value of a filter like "MeanRating==1.2" is parsed/converted and the current CultureInfo is e.g. de-DE, then the conversion fails with an exception, because 1.2 is not a valid format in culture.

So it would be good, to let the developer decide which CultureInfo should be used by Sieve.

Therefore this pull request added a CultureInfo property to the SieveOptions, that is used in the Apply method of the SieveProcessor to change the current culture during processing.

@hasanmanzak hasanmanzak self-requested a review February 23, 2023 01:46
Copy link
Collaborator

@hasanmanzak hasanmanzak left a comment

Choose a reason for hiding this comment

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

I'm sorry but I can not approve this, at least as-is. CultureInfo manupulation is risky and very open-ended. One can ask for value encapsulation like filters=field==((en-en)data), field2!=currentCulturedData, or full query encapsulation like filters=field==data, field2!=data2&culture=en-en or a global sieve startup parameter. We should consider this widely and then we should implement such support.

By the way, there is a PR (#79) opened about almost 4 years ago. We did resolved the conflicts with another one (#125) and asked for some unit tests. Maybe you can keep on going on that path? What'd you say? 😄

@@ -13,5 +15,7 @@ public class SieveOptions
public bool IgnoreNullsOnNotEqual { get; set; } = true;

public bool DisableNullableTypeExpressionForSorting { get; set; } = false;

public CultureInfo CultureInfo { get; set; } = CultureInfo.CurrentCulture;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to have this setting to be a string which can be read from appsettings.json.

Copy link
Author

Choose a reason for hiding this comment

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

You are right. Fixed it with solution from #125

Comment on lines 126 to 127
var currentCultureInfo = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = Options.Value.CultureInfo;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Errm, no, please.. You should not alter the current culture!..

Copy link
Author

Choose a reason for hiding this comment

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

You're right. Really bad :-) Also fixed with solution from #125

@smashlines
Copy link
Author

I'm sorry but I can not approve this, at least as-is. CultureInfo manupulation is risky and very open-ended. One can ask for value encapsulation like filters=field==((en-en)data), field2!=currentCulturedData, or full query encapsulation like filters=field==data, field2!=data2&culture=en-en or a global sieve startup parameter. We should consider this widely and then we should implement such support.

By the way, there is a PR (#79) opened about almost 4 years ago. We did resolved the conflicts with another one (#125) and asked for some unit tests. Maybe you can keep on going on that path? What'd you say? 😄

Hi, I did what you proposed. So now this PR includes the solution from #125 extended with test cases

@smashlines smashlines closed this Nov 11, 2023
@smashlines smashlines deleted the master branch November 11, 2023 15:58
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