示例#1
0
        public static IDisposable EnZa()
        {
            var culture = new ThreadCultureParameters
            {
                CurrencyDecimalDigits    = 2,
                CurrencyDecimalSeparator = ".",
                CurrencySymbol           = "R",
                NumberDecimalDigits      = 2,
                NumberDecimalSeparator   = ".",
                PercentDecimalDigits     = 2,
                PercentDecimalSeparator  = ".",
                PercentSymbol            = "%",
                ShortDatePattern         = "yyyy/MM/dd",
                ShortTimePattern         = "HH:mm",
                DateSeparator            = "/",
                TimeSeparator            = ":"
            };

            return(new CultureDisposable("en-za", culture));
        }
示例#2
0
        public static void SetDefaultSystemCultureToEnZa()
        {
            var culture = new ThreadCultureParameters
            {
                CurrencyDecimalDigits    = 2,
                CurrencyDecimalSeparator = ".",
                CurrencySymbol           = "R",
                NumberDecimalDigits      = 2,
                NumberDecimalSeparator   = ".",
                PercentDecimalDigits     = 2,
                PercentDecimalSeparator  = ".",
                PercentSymbol            = "%",
                ShortDatePattern         = "yyyy/MM/dd",
                ShortTimePattern         = "HH:mm",
                DateSeparator            = "/",
                TimeSeparator            = ":"
            };

// ReSharper disable once ObjectCreationAsStatement    Note the creation of the new CultureBase below will force the current thread culture to be set
            new CultureBase("en-za", culture);
            CultureInfo.DefaultThreadCurrentCulture = Thread.CurrentThread.CurrentCulture;
        }
示例#3
0
 public CultureDisposable(string culture, ThreadCultureParameters overrideThreadCultureParameters = null)
     : base(culture, overrideThreadCultureParameters)
 {
     _originalCulture   = Thread.CurrentThread.CurrentCulture;
     _originalUiCulture = Thread.CurrentThread.CurrentUICulture;
 }
示例#4
0
            public CultureBase(string culture, ThreadCultureParameters overrideThreadCultureParameters = null)
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo(culture);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
                if (overrideThreadCultureParameters.IsNull())
                {
                    return;
                }

// ReSharper disable PossibleNullReferenceException
                if (overrideThreadCultureParameters.ShortDatePattern.NotNullOrEmptyTrimmed())
                {
// ReSharper restore PossibleNullReferenceException
                    Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = overrideThreadCultureParameters.ShortDatePattern;
                }
                if (overrideThreadCultureParameters.DateSeparator.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.DateTimeFormat.DateSeparator = overrideThreadCultureParameters.DateSeparator;
                }
                if (overrideThreadCultureParameters.ShortTimePattern.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = overrideThreadCultureParameters.ShortTimePattern;
                }
                if (overrideThreadCultureParameters.TimeSeparator.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.DateTimeFormat.TimeSeparator = overrideThreadCultureParameters.TimeSeparator;
                }

                if (overrideThreadCultureParameters.CurrencySymbol.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol = overrideThreadCultureParameters.CurrencySymbol;
                }
                if (overrideThreadCultureParameters.CurrencyDecimalSeparator.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = overrideThreadCultureParameters.CurrencyDecimalSeparator;
                }
                if (overrideThreadCultureParameters.CurrencyDecimalDigits > 0)
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalDigits = overrideThreadCultureParameters.CurrencyDecimalDigits;
                }

                //See https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencynegativepattern(v=vs.110).aspx
                Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyNegativePattern = 9;
                //See https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencypositivepattern(v=vs.110).aspx
                Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyPositivePattern = 2;

                if (overrideThreadCultureParameters.PercentSymbol.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.PercentSymbol = overrideThreadCultureParameters.PercentSymbol;
                }
                if (overrideThreadCultureParameters.PercentDecimalSeparator.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.PercentDecimalSeparator = overrideThreadCultureParameters.PercentDecimalSeparator;
                }
                if (overrideThreadCultureParameters.PercentDecimalDigits > 0)
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.PercentDecimalDigits = overrideThreadCultureParameters.PercentDecimalDigits;
                }

                if (overrideThreadCultureParameters.NumberDecimalSeparator.NotNullOrEmptyTrimmed())
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = overrideThreadCultureParameters.NumberDecimalSeparator;
                }
                if (overrideThreadCultureParameters.NumberDecimalDigits > 0)
                {
                    Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalDigits = overrideThreadCultureParameters.NumberDecimalDigits;
                }
            }