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 public static RegionInfo CurrentRegion {
44 if (currentRegion == null) {
45 CultureInfo ci = CultureInfo.CurrentCulture;
47 return currentRegion = new RegionInfo (ci);
50 currentRegion = CreateFromNSLocale ();
57 // the following (instance) fields must be _first_ and stay synchronized
58 // with the mono's MonoRegionInfo defined in mono/metadata/object-internals.h
59 #pragma warning disable 649
66 string currencySymbol;
67 string isoCurrencySymbol;
68 string currencyEnglishName;
69 string currencyNativeName;
70 #pragma warning restore 649
72 public RegionInfo (int culture)
74 if (!GetByTerritory (CultureInfo.GetCultureInfo (culture)))
75 throw new ArgumentException (
76 String.Format ("Region ID {0} (0x{0:X4}) is not a supported region.", culture), "culture");
79 public RegionInfo (string name)
82 throw new ArgumentNullException ();
84 if (construct_internal_region_from_name (name.ToUpperInvariant ())) {
87 if (!GetByTerritory (CultureInfo.GetCultureInfo (name)))
88 throw new ArgumentException (String.Format ("Region name {0} is not supported.", name), "name");
91 RegionInfo (CultureInfo ci)
93 if (ci.LCID == CultureInfo.InvariantCultureId) {
98 nativeName = englishName = "Invariant Country";
99 currencySymbol = "\u00A4";
100 isoCurrencySymbol ="XDR";
101 currencyEnglishName = currencyNativeName = "International Monetary Fund";
105 if (ci.Territory == null)
106 throw new NotImplementedException ("Neutral region info");
108 construct_internal_region_from_name (ci.Territory.ToUpperInvariant ());
111 bool GetByTerritory (CultureInfo ci)
114 throw new Exception ("INTERNAL ERROR: should not happen.");
115 if (ci.IsNeutralCulture || ci.Territory == null)
118 return construct_internal_region_from_name (ci.Territory.ToUpperInvariant ());
121 [MethodImplAttribute (MethodImplOptions.InternalCall)]
122 private extern bool construct_internal_region_from_name (string name);
124 [System.Runtime.InteropServices.ComVisible(false)]
125 public virtual string CurrencyEnglishName {
126 get { return currencyEnglishName; }
129 public virtual string CurrencySymbol {
130 get { return currencySymbol; }
133 [MonoTODO ("DisplayName currently only returns the EnglishName")]
134 public virtual string DisplayName {
135 get { return englishName; }
138 public virtual string EnglishName {
139 get { return englishName; }
142 [System.Runtime.InteropServices.ComVisible(false)]
143 public virtual int GeoId {
144 get { return regionId; }
147 public virtual bool IsMetric {
159 public virtual string ISOCurrencySymbol {
160 get { return isoCurrencySymbol; }
164 public virtual string NativeName {
165 get { return nativeName; }
169 public virtual string CurrencyNativeName {
170 get { return currencyNativeName; }
173 public virtual string Name {
174 get { return iso2Name; }
177 public virtual string ThreeLetterISORegionName {
178 get { return iso3Name; }
181 public virtual string ThreeLetterWindowsRegionName {
182 get { return win3Name; }
185 public virtual string TwoLetterISORegionName {
186 get { return iso2Name; }
189 public override bool Equals (object value)
191 RegionInfo other = value as RegionInfo;
192 return other != null && Name == other.Name;
195 public override int GetHashCode ()
197 return Name.GetHashCode ();
200 public override string ToString ()