2 // System.Globalization.RegionInfo.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Runtime.CompilerServices;
31 using System.Runtime.InteropServices;
33 namespace System.Globalization
35 [System.Runtime.InteropServices.ComVisible(true)]
37 [StructLayout (LayoutKind.Sequential)]
38 public partial class RegionInfo
40 static RegionInfo currentRegion;
42 // This property is not synchronized with CurrentCulture, so
43 // we need to use bootstrap CurrentCulture LCID.
44 public static RegionInfo CurrentRegion {
46 if (currentRegion == null) {
47 // make sure to fill BootstrapCultureID.
48 CultureInfo ci = CultureInfo.CurrentCulture;
49 // If current culture is invariant then region is not available.
50 if (ci != null && CultureInfo.BootstrapCultureID != 0x7F)
51 currentRegion = new RegionInfo (CultureInfo.BootstrapCultureID);
54 currentRegion = CreateFromNSLocale ();
63 // the following (instance) fields must be _first_ and stay synchronized
64 // with the mono's MonoRegionInfo defined in mono/metadata/object-internals.h
65 #pragma warning disable 649
71 string currencySymbol;
72 string isoCurrencySymbol;
73 string currencyEnglishName;
74 #pragma warning restore 649
76 // new (instance) fields should be added here (and do not have to be duplicated in the runtime)
78 int lcid; // it is used only for Equals() (not even used in GetHashCode()).
80 public RegionInfo (int culture)
82 if (!GetByTerritory (CultureInfo.GetCultureInfo (culture)))
83 throw new ArgumentException (
84 String.Format ("Region ID {0} (0x{0:X4}) is not a supported region.", culture), "culture");
87 public RegionInfo (string name)
90 throw new ArgumentNullException ();
92 if (construct_internal_region_from_name (name.ToUpperInvariant ())) {
93 lcid = name.GetHashCode (); // random-ish
96 if (!GetByTerritory (CultureInfo.GetCultureInfo (name)))
97 throw new ArgumentException (String.Format ("Region name {0} is not supported.", name), "name");
100 bool GetByTerritory (CultureInfo ci)
103 throw new Exception ("INTERNAL ERROR: should not happen.");
104 if (ci.IsNeutralCulture || ci.Territory == null)
107 return construct_internal_region_from_name (ci.Territory.ToUpperInvariant ());
110 [MethodImplAttribute (MethodImplOptions.InternalCall)]
111 private extern bool construct_internal_region_from_name (string name);
113 [System.Runtime.InteropServices.ComVisible(false)]
114 public virtual string CurrencyEnglishName {
115 get { return currencyEnglishName; }
118 public virtual string CurrencySymbol {
119 get { return currencySymbol; }
122 [MonoTODO ("DisplayName currently only returns the EnglishName")]
123 public virtual string DisplayName {
124 get { return englishName; }
127 public virtual string EnglishName {
128 get { return englishName; }
131 [System.Runtime.InteropServices.ComVisible(false)]
132 public virtual int GeoId {
133 get { return regionId; }
136 public virtual bool IsMetric {
148 public virtual string ISOCurrencySymbol {
149 get { return isoCurrencySymbol; }
152 [System.Runtime.InteropServices.ComVisible(false)]
153 public virtual string NativeName {
154 get { return DisplayName; }
157 [MonoTODO ("Not implemented")]
158 [System.Runtime.InteropServices.ComVisible(false)]
159 public virtual string CurrencyNativeName {
160 get { throw new NotImplementedException (); }
163 public virtual string Name {
164 get { return iso2Name; }
167 public virtual string ThreeLetterISORegionName {
168 get { return iso3Name; }
171 public virtual string ThreeLetterWindowsRegionName {
172 get { return win3Name; }
175 public virtual string TwoLetterISORegionName {
176 get { return iso2Name; }
182 public override bool Equals (object value)
184 RegionInfo other = value as RegionInfo;
185 return other != null && lcid == other.lcid;
188 public override int GetHashCode ()
190 return (int) (0x80000000 + (regionId << 3) + regionId); // it i still based on regionId
193 public override string ToString ()