2 // System.Globalization.RegionInfo.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Marek Safar (marek.safar@gmail.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.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
72 string currencySymbol;
73 string isoCurrencySymbol;
74 string currencyEnglishName;
75 string currencyNativeName;
76 #pragma warning restore 649
78 public RegionInfo (int culture)
80 if (!GetByTerritory (CultureInfo.GetCultureInfo (culture)))
81 throw new ArgumentException (
82 String.Format ("Region ID {0} (0x{0:X4}) is not a supported region.", culture), "culture");
85 public RegionInfo (string name)
88 throw new ArgumentNullException ();
90 if (construct_internal_region_from_name (name.ToUpperInvariant ())) {
93 if (!GetByTerritory (CultureInfo.GetCultureInfo (name)))
94 throw new ArgumentException (String.Format ("Region name {0} is not supported.", name), "name");
97 bool GetByTerritory (CultureInfo ci)
100 throw new Exception ("INTERNAL ERROR: should not happen.");
101 if (ci.IsNeutralCulture || ci.Territory == null)
104 return construct_internal_region_from_name (ci.Territory.ToUpperInvariant ());
107 [MethodImplAttribute (MethodImplOptions.InternalCall)]
108 private extern bool construct_internal_region_from_name (string name);
110 [System.Runtime.InteropServices.ComVisible(false)]
111 public virtual string CurrencyEnglishName {
112 get { return currencyEnglishName; }
115 public virtual string CurrencySymbol {
116 get { return currencySymbol; }
119 [MonoTODO ("DisplayName currently only returns the EnglishName")]
120 public virtual string DisplayName {
121 get { return englishName; }
124 public virtual string EnglishName {
125 get { return englishName; }
128 [System.Runtime.InteropServices.ComVisible(false)]
129 public virtual int GeoId {
130 get { return regionId; }
133 public virtual bool IsMetric {
145 public virtual string ISOCurrencySymbol {
146 get { return isoCurrencySymbol; }
150 public virtual string NativeName {
151 get { return nativeName; }
155 public virtual string CurrencyNativeName {
156 get { return currencyNativeName; }
159 public virtual string Name {
160 get { return iso2Name; }
163 public virtual string ThreeLetterISORegionName {
164 get { return iso3Name; }
167 public virtual string ThreeLetterWindowsRegionName {
168 get { return win3Name; }
171 public virtual string TwoLetterISORegionName {
172 get { return iso2Name; }
175 public override bool Equals (object value)
177 RegionInfo other = value as RegionInfo;
178 return other != null && Name == other.Name;
181 public override int GetHashCode ()
183 return Name.GetHashCode ();
186 public override string ToString ()