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.Globalization;
31 using System.Runtime.CompilerServices;
33 namespace System.Globalization
36 [System.Runtime.InteropServices.ComVisible(true)]
39 public class RegionInfo
41 static RegionInfo currentRegion;
43 // This property is not synchronized with CurrentCulture, so
44 // we need to use bootstrap CurrentCulture LCID.
45 public static RegionInfo CurrentRegion {
47 if (currentRegion == null) {
48 // make sure to fill BootstrapCultureID.
49 CultureInfo ci = CultureInfo.CurrentCulture;
50 // If current culture is invariant then region is not available.
51 if (ci == null || CultureInfo.BootstrapCultureID == 0x7F)
53 currentRegion = new RegionInfo (CultureInfo.BootstrapCultureID);
59 int lcid; // it is used only for Equals() (not even used in GetHashCode()).
65 string currencySymbol;
66 string isoCurrencySymbol;
67 string currencyEnglishName;
69 public RegionInfo (int lcid)
72 if (!GetByTerritory (CultureInfo.GetCultureInfo (lcid)))
73 throw new ArgumentException (
74 String.Format ("Region ID {0} (0x{0:X4}) is not a supported region.", lcid), "lcid");
76 if (!construct_internal_region_from_lcid (lcid))
77 throw new ArgumentException (
78 String.Format ("Region ID {0} (0x{0:X4}) is not a " +
79 "supported region.", lcid), "lcid");
83 public RegionInfo (string name)
86 throw new ArgumentNullException ();
89 if (construct_internal_region_from_name (name.ToUpperInvariant ())) {
90 lcid = name.GetHashCode (); // random-ish
93 if (!GetByTerritory (CultureInfo.GetCultureInfo (name)))
94 throw new ArgumentException (String.Format ("Region name {0} is not supported.", name), "name");
96 if (!construct_internal_region_from_name (name.ToUpperInvariant ()))
97 throw new ArgumentException ("Region name " + name +
98 " is not supported.", "name");
102 bool GetByTerritory (CultureInfo ci)
105 throw new Exception ("INTERNAL ERROR: should not happen.");
106 if (ci.IsNeutralCulture || ci.Territory == null)
109 return construct_internal_region_from_name (ci.Territory.ToUpperInvariant ());
112 [MethodImplAttribute (MethodImplOptions.InternalCall)]
113 private extern bool construct_internal_region_from_lcid (int lcid);
115 [MethodImplAttribute (MethodImplOptions.InternalCall)]
116 private extern bool construct_internal_region_from_name (string name);
119 [System.Runtime.InteropServices.ComVisible(false)]
120 public virtual string CurrencyEnglishName {
121 get { return currencyEnglishName; }
125 public virtual string CurrencySymbol {
126 get { return currencySymbol; }
129 [MonoTODO ("DisplayName currently only returns the EnglishName")]
130 public virtual string DisplayName {
131 get { return englishName; }
134 public virtual string EnglishName {
135 get { return englishName; }
139 public virtual int GeoId {
140 get { return regionId; }
144 public virtual bool IsMetric {
156 public virtual string ISOCurrencySymbol {
157 get { return isoCurrencySymbol; }
161 [System.Runtime.InteropServices.ComVisible(false)]
162 public virtual string NativeName {
163 get { return DisplayName; }
166 [MonoTODO ("Not implemented")]
167 public virtual string CurrencyNativeName {
168 get { throw new NotImplementedException (); }
172 public virtual string Name {
173 get { return iso2Name; }
176 public virtual string ThreeLetterISORegionName {
177 get { return iso3Name; }
180 public virtual string ThreeLetterWindowsRegionName {
181 get { return win3Name; }
184 public virtual string TwoLetterISORegionName {
185 get { return iso2Name; }
192 public override bool Equals (object value)
194 RegionInfo other = value as RegionInfo;
195 return other != null && lcid == other.lcid;
198 public override int GetHashCode ()
200 return (int) (0x80000000 + (regionId << 3) + regionId); // it i still based on regionId
203 public override bool Equals (object value)
205 RegionInfo other = value as RegionInfo;
206 return other != null && regionId == other.regionId;
209 public override int GetHashCode () {
214 public override string ToString ()