I have a lot of code in a class library that does not indicate CultureInfo.InvariantCulture. For example, in operations toString, toBool, toInt, etc.
CultureInfo.InvariantCulture
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))
, - ; , - . , , , , . , , Convert calls - , , , ; " ".
, , ; , , . , , :
private static readonly IFormatProvider parseFormat = CultureInfo.InvariantCulture;
. IFormatProvider , , . IMHO, .
Parse/Convert, Convert.ToXxx , . : .
, CultureInfo :
Console.WriteLine(double.Parse("1.000")); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Console.WriteLine(double.Parse("1.000"));
( ):
1000 1
, ?
Source: https://habr.com/ru/post/1743612/More articles:Data validation minLength does not work with Auth component for CakePHP - authenticationПомощь в jQuery - jqueryJava: repetition, overuse - problem? - javaWhat is a root reference? - garbage-collectionКакой правильный способ использовать ARM SIMD для iPhone для игры в вектор/матрицу? - mathМассив объектов в основной структуре данных? - cocoahow can i pass parameter to linq query - linq-to-sqlQLabel: interlinea / linespacing in WordWrap mode - qtPHP vs Phpmyadmin - phpIs it advisable to store things like a list of cities on db? - cakephpAll Articles