disable broken tests on net_4_0
[mcs.git] / class / corlib / System.Globalization / RegionInfo.cs
blob68526bffc3b71d294be226bf51904097c51090a6
1 //
2 // System.Globalization.RegionInfo.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
8 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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
35 [System.Runtime.InteropServices.ComVisible(true)]
36 [Serializable]
37 public class RegionInfo
39 static RegionInfo currentRegion;
41 // This property is not synchronized with CurrentCulture, so
42 // we need to use bootstrap CurrentCulture LCID.
43 public static RegionInfo CurrentRegion {
44 get {
45 if (currentRegion == null) {
46 // make sure to fill BootstrapCultureID.
47 CultureInfo ci = CultureInfo.CurrentCulture;
48 // If current culture is invariant then region is not available.
49 if (ci == null || CultureInfo.BootstrapCultureID == 0x7F)
50 return null;
51 currentRegion = new RegionInfo (CultureInfo.BootstrapCultureID);
53 return currentRegion;
57 int lcid; // it is used only for Equals() (not even used in GetHashCode()).
59 #pragma warning disable 649
60 int regionId;
61 string iso2Name;
62 string iso3Name;
63 string win3Name;
64 string englishName;
65 string currencySymbol;
66 string isoCurrencySymbol;
67 string currencyEnglishName;
68 #pragma warning restore 649
70 public RegionInfo (int culture)
72 if (!GetByTerritory (CultureInfo.GetCultureInfo (culture)))
73 throw new ArgumentException (
74 String.Format ("Region ID {0} (0x{0:X4}) is not a supported region.", culture), "culture");
77 public RegionInfo (string name)
79 if (name == null)
80 throw new ArgumentNullException ();
82 if (construct_internal_region_from_name (name.ToUpperInvariant ())) {
83 lcid = name.GetHashCode (); // random-ish
84 return;
86 if (!GetByTerritory (CultureInfo.GetCultureInfo (name)))
87 throw new ArgumentException (String.Format ("Region name {0} is not supported.", name), "name");
90 bool GetByTerritory (CultureInfo ci)
92 if (ci == null)
93 throw new Exception ("INTERNAL ERROR: should not happen.");
94 if (ci.IsNeutralCulture || ci.Territory == null)
95 return false;
96 this.lcid = ci.LCID;
97 return construct_internal_region_from_name (ci.Territory.ToUpperInvariant ());
100 [MethodImplAttribute (MethodImplOptions.InternalCall)]
101 private extern bool construct_internal_region_from_name (string name);
103 [System.Runtime.InteropServices.ComVisible(false)]
104 public virtual string CurrencyEnglishName {
105 get { return currencyEnglishName; }
108 public virtual string CurrencySymbol {
109 get { return currencySymbol; }
112 [MonoTODO ("DisplayName currently only returns the EnglishName")]
113 public virtual string DisplayName {
114 get { return englishName; }
117 public virtual string EnglishName {
118 get { return englishName; }
121 [System.Runtime.InteropServices.ComVisible(false)]
122 public virtual int GeoId {
123 get { return regionId; }
126 public virtual bool IsMetric {
127 get {
128 switch (iso2Name) {
129 case "US":
130 case "UK":
131 return false;
132 default:
133 return true;
138 public virtual string ISOCurrencySymbol {
139 get { return isoCurrencySymbol; }
142 [System.Runtime.InteropServices.ComVisible(false)]
143 public virtual string NativeName {
144 get { return DisplayName; }
147 [MonoTODO ("Not implemented")]
148 [System.Runtime.InteropServices.ComVisible(false)]
149 public virtual string CurrencyNativeName {
150 get { throw new NotImplementedException (); }
153 public virtual string Name {
154 get { return iso2Name; }
157 public virtual string ThreeLetterISORegionName {
158 get { return iso3Name; }
161 public virtual string ThreeLetterWindowsRegionName {
162 get { return win3Name; }
165 public virtual string TwoLetterISORegionName {
166 get { return iso2Name; }
170 // methods
172 public override bool Equals (object value)
174 RegionInfo other = value as RegionInfo;
175 return other != null && lcid == other.lcid;
178 public override int GetHashCode ()
180 return (int) (0x80000000 + (regionId << 3) + regionId); // it i still based on regionId
183 public override string ToString ()
185 return Name;