Add this for backwards compatibility
[mono.git] / mcs / class / corlib / System.Globalization / RegionInfo.cs
1 //
2 // RegionInfo.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
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.
29 //
30 using System.Globalization;
31 using System.Runtime.CompilerServices;
32
33 namespace System.Globalization
34 {
35 #if NET_2_0
36         [System.Runtime.InteropServices.ComVisible(true)]
37 #endif
38         [Serializable]
39         public class RegionInfo
40         {
41                 static RegionInfo currentRegion;
42
43                 // This property is not synchronized with CurrentCulture, so
44                 // we need to use bootstrap CurrentCulture LCID.
45                 public static RegionInfo CurrentRegion {
46                         get {
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)
52                                                 return null;
53                                         currentRegion = new RegionInfo (CultureInfo.BootstrapCultureID);
54                                 }
55                                 return currentRegion;
56                         }
57                 }
58
59                 int regionId;
60                 string iso2Name;
61                 string iso3Name;
62                 string win3Name;
63                 string englishName;
64                 string currencySymbol;
65                 string isoCurrencySymbol;
66                 string currencyEnglishName;
67
68                 public RegionInfo (int lcid)
69                 {
70                         if (!construct_internal_region_from_lcid (lcid))
71                                 throw new ArgumentException (
72                                         String.Format ("Region ID {0} (0x{0:X4}) is not a " +
73                                                         "supported region.", lcid), "lcid");
74                 }
75
76                 public RegionInfo (string name)
77                 {
78                         if (name == null)
79                                 throw new ArgumentNullException ();
80
81                         if (!construct_internal_region_from_name (name.ToUpperInvariant ()))
82                                 throw new ArgumentException ("Region name " + name +
83                                                 " is not supported.", "name");
84                 }
85
86                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
87                 private extern bool construct_internal_region_from_lcid (int lcid);
88
89                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
90                 private extern bool construct_internal_region_from_name (string name);
91
92 #if NET_2_0
93                 [System.Runtime.InteropServices.ComVisible(false)]
94                 public virtual string CurrencyEnglishName {
95                         get { return currencyEnglishName; }
96                 }
97 #endif
98
99                 public virtual string CurrencySymbol {
100                         get { return currencySymbol; }
101                 }
102
103                 [MonoTODO]
104                 public virtual string DisplayName {
105                         get { return englishName; }
106                 }
107
108                 public virtual string EnglishName {
109                         get { return englishName; }
110                 }
111
112                 public virtual bool IsMetric {
113                         get {
114                                 switch (iso2Name) {
115                                 case "US":
116                                 case "UK":
117                                         return false;
118                                 default:
119                                         return true;
120                                 }
121                         }
122                 }
123
124                 public virtual string ISOCurrencySymbol {
125                         get { return isoCurrencySymbol; }
126                 }
127
128 #if NET_2_0
129                 [MonoTODO]
130                 [System.Runtime.InteropServices.ComVisible(false)]
131                 public virtual string NativeName {
132                         get { return DisplayName; }
133                 }
134
135                 [MonoTODO]
136                 public virtual string CurrencyNativeName {
137                         get { throw new NotImplementedException (); }
138                 }
139 #endif
140
141                 public virtual string Name {
142                         get { return iso2Name; }
143                 }
144
145                 public virtual string ThreeLetterISORegionName {
146                         get { return iso3Name; }
147                 }
148
149                 public virtual string ThreeLetterWindowsRegionName {
150                         get { return win3Name; }
151                 }
152                 
153                 public virtual string TwoLetterISORegionName {
154                         get { return iso2Name; }
155                 }
156
157                 //
158                 // methods
159
160 #if NET_2_0
161 #else
162                 public override bool Equals (object value)
163                 {
164                         RegionInfo other = value as RegionInfo;
165                         return other != null && regionId == other.regionId;
166                 }
167
168                 public override int GetHashCode () {
169                         return regionId;
170                 }
171 #endif
172
173                 public override string ToString ()
174                 {
175                         return Name;
176                 }
177         }
178 }