Is there a way to install a DLL to always follow CultureInfo.InvariantCulture by default, if not specified?

I have a lot of code in a class library that does not indicate CultureInfo.InvariantCulture. For example, in operations toString, toBool, toInt, etc.

Is there a way to get a property for a class library to always execute with CultureInfo.InvariantCulture, even if it is not explicitly specified everywhere in the code?

How is the global switch?

It is not necessary to randomly enter it every time, this makes my code less readable and, for example, is a great pain:

if (Convert.ToInt16(task.RetryCount, CultureInfo.InvariantCulture) <
            Convert.ToInt16(ConfigurationManager.AppSettings["TasksMaxRetry"], CultureInfo.InvariantCulture))
+3
source share
2 answers

, - ; , - . , , , , . , , Convert calls - , , , ; " ".

, , ; , , . , , :

private static readonly IFormatProvider parseFormat = CultureInfo.InvariantCulture;

. IFormatProvider , , . IMHO, .

Parse/Convert, Convert.ToXxx , . : .

+6

, CultureInfo :

Console.WriteLine(double.Parse("1.000"));
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Console.WriteLine(double.Parse("1.000"));

( ):

1000
1

, ?

+3

Source: https://habr.com/ru/post/1743612/


All Articles