[Mono-dev] patches for RegionInfo support

Atsushi Eno atsushi at ximian.com
Mon Aug 22 07:32:52 EDT 2005


Hi,

> You are misinterpreting CurrentRegion.
> CurrentRegion is no way related to CurrentCulture.

Well, I didn't think CurrentRegion is not in sync with CurrentCulture
(as I explicitly commented in RegionInfo.cs), but yeah the previous
code was still incorrect that treated possibly different region
than CultureInfo.BootstrapCultureID.

> RegionInfo.CurrentRegion:
> http://msdn2.microsoft.com/library/7kcxkdc9(en-us,vs.80).aspx
> 
> The documentation describes the actual behaviour of CurrentRegion (I have
> done some tests):
> 
> The value is AppDomain scoped (in other words stored in a static filed). A
> single instance is constructed at the first call to CurrentRegion then a

Hrm, it sounds true:

--------
using System;
using System.Globalization;
using System.Threading;

public class Test
{
         static RegionInfo staticRegion;

         public static void Main ()
         {
                 RegionInfo r = RegionInfo.CurrentRegion;
                 Console.WriteLine (r);
                 Thread.CurrentThread.CurrentCulture = new CultureInfo 
("en-US");
                 r = RegionInfo.CurrentRegion;
                 Console.WriteLine (r);

                 staticRegion = RegionInfo.CurrentRegion;
                 Console.WriteLine (staticRegion ==
			RegionInfo.CurrentRegion);

                 Thread t = new Thread (new ThreadStart (Another));
                 t.Start ();
         }

         static void Another ()
         {
                 Console.WriteLine (staticRegion ==
			RegionInfo.CurrentRegion);
         }
}
--------

> cached value is retruned. On Windows this is based on the value selected in
> "Regional and Language Options". This is per-user setting on Windows and 
> can
> be retrieved using GetUserDefaultLCID. You can change however this setting
> (on Windows) without rebooting so the value may change. But it will have no
> effect to CurrentRegion if it's already cached unless you call
> CultureInfo.ClearCachedData.

OK. actually ClearCachedData() seems not working fine, so it should be
fixed anyways.

> And CurrentRegion is read-only.

Yes, as there is no setter.

> At the beginning I said that "CurrentRegion is no way related to
> CurrentCulture.". This is true but I don't know other OS' internals
> regarding RegionInfo so using CultureInfo may be required but CurrentRegion
> is an AppDomain scope cached value that will be refreshed only when calling
> ClearCachedData. So CurrentCulture should not be used as it can be changed
> but the default value for CurrentCulture can be used if it's required.

I think it would be OK just to be equal to what things are done on
Windows since no one uses it ;-)

Atsushi Eno



More information about the Mono-devel-list mailing list