mscorlib(4.0.0.0) API with additions
RegionInfo.cs
3 using System.Security;
4 
5 namespace System.Globalization
6 {
9  [ComVisible(true)]
10  [__DynamicallyInvokable]
11  public class RegionInfo
12  {
13  internal string m_name;
14 
15  [NonSerialized]
16  internal CultureData m_cultureData;
17 
18  internal static volatile RegionInfo s_currentRegionInfo;
19 
20  [OptionalField(VersionAdded = 2)]
21  private int m_cultureId;
22 
23  [OptionalField(VersionAdded = 2)]
24  internal int m_dataItem;
25 
26  private static readonly int[] IdFromEverettRegionInfoDataItem = new int[110]
27  {
28  14337,
29  1052,
30  1067,
31  11274,
32  3079,
33  3081,
34  1068,
35  2060,
36  1026,
37  15361,
38  2110,
39  16394,
40  1046,
41  1059,
42  10249,
43  3084,
44  9225,
45  2055,
46  13322,
47  2052,
48  9226,
49  5130,
50  1029,
51  1031,
52  1030,
53  7178,
54  5121,
55  12298,
56  1061,
57  3073,
58  1027,
59  1035,
60  1080,
61  1036,
62  2057,
63  1079,
64  1032,
65  4106,
66  3076,
67  18442,
68  1050,
69  1038,
70  1057,
71  6153,
72  1037,
73  1081,
74  2049,
75  1065,
76  1039,
77  1040,
78  8201,
79  11265,
80  1041,
81  1089,
82  1088,
83  1042,
84  13313,
85  1087,
86  12289,
87  5127,
88  1063,
89  4103,
90  1062,
91  4097,
92  6145,
93  6156,
94  1071,
95  1104,
96  5124,
97  1125,
98  2058,
99  1086,
100  19466,
101  1043,
102  1044,
103  5129,
104  8193,
105  6154,
106  10250,
107  13321,
108  1056,
109  1045,
110  20490,
111  2070,
112  15370,
113  16385,
114  1048,
115  1049,
116  1025,
117  1053,
118  4100,
119  1060,
120  1051,
121  2074,
122  17418,
123  1114,
124  1054,
125  7169,
126  1055,
127  11273,
128  1028,
129  1058,
130  1033,
131  14346,
132  1091,
133  8202,
134  1066,
135  9217,
136  1078,
137  12297
138  };
139 
142  [__DynamicallyInvokable]
143  public static RegionInfo CurrentRegion
144  {
145  [SecuritySafeCritical]
146  [__DynamicallyInvokable]
147  get
148  {
149  RegionInfo regionInfo = s_currentRegionInfo;
150  if (regionInfo == null)
151  {
152  regionInfo = new RegionInfo(CultureInfo.CurrentCulture.m_cultureData);
153  regionInfo.m_name = regionInfo.m_cultureData.SREGIONNAME;
154  s_currentRegionInfo = regionInfo;
155  }
156  return regionInfo;
157  }
158  }
159 
162  [__DynamicallyInvokable]
163  public virtual string Name
164  {
165  [__DynamicallyInvokable]
166  get
167  {
168  return m_name;
169  }
170  }
171 
174  [__DynamicallyInvokable]
175  public virtual string EnglishName
176  {
177  [SecuritySafeCritical]
178  [__DynamicallyInvokable]
179  get
180  {
181  return m_cultureData.SENGCOUNTRY;
182  }
183  }
184 
187  [__DynamicallyInvokable]
188  public virtual string DisplayName
189  {
190  [SecuritySafeCritical]
191  [__DynamicallyInvokable]
192  get
193  {
194  return m_cultureData.SLOCALIZEDCOUNTRY;
195  }
196  }
197 
200  [ComVisible(false)]
201  [__DynamicallyInvokable]
202  public virtual string NativeName
203  {
204  [SecuritySafeCritical]
205  [__DynamicallyInvokable]
206  get
207  {
208  return m_cultureData.SNATIVECOUNTRY;
209  }
210  }
211 
214  [__DynamicallyInvokable]
215  public virtual string TwoLetterISORegionName
216  {
217  [SecuritySafeCritical]
218  [__DynamicallyInvokable]
219  get
220  {
221  return m_cultureData.SISO3166CTRYNAME;
222  }
223  }
224 
227  public virtual string ThreeLetterISORegionName
228  {
229  [SecuritySafeCritical]
230  get
231  {
232  return m_cultureData.SISO3166CTRYNAME2;
233  }
234  }
235 
238  public virtual string ThreeLetterWindowsRegionName
239  {
240  [SecuritySafeCritical]
241  get
242  {
243  return m_cultureData.SABBREVCTRYNAME;
244  }
245  }
246 
250  [__DynamicallyInvokable]
251  public virtual bool IsMetric
252  {
253  [__DynamicallyInvokable]
254  get
255  {
256  int iMEASURE = m_cultureData.IMEASURE;
257  return iMEASURE == 0;
258  }
259  }
260 
263  [ComVisible(false)]
264  public virtual int GeoId
265  {
266  get
267  {
268  return m_cultureData.IGEOID;
269  }
270  }
271 
274  [ComVisible(false)]
275  public virtual string CurrencyEnglishName
276  {
277  [SecuritySafeCritical]
278  get
279  {
280  return m_cultureData.SENGLISHCURRENCY;
281  }
282  }
283 
286  [ComVisible(false)]
287  public virtual string CurrencyNativeName
288  {
289  [SecuritySafeCritical]
290  get
291  {
292  return m_cultureData.SNATIVECURRENCY;
293  }
294  }
295 
298  [__DynamicallyInvokable]
299  public virtual string CurrencySymbol
300  {
301  [SecuritySafeCritical]
302  [__DynamicallyInvokable]
303  get
304  {
305  return m_cultureData.SCURRENCY;
306  }
307  }
308 
311  [__DynamicallyInvokable]
312  public virtual string ISOCurrencySymbol
313  {
314  [SecuritySafeCritical]
315  [__DynamicallyInvokable]
316  get
317  {
318  return m_cultureData.SINTLSYMBOL;
319  }
320  }
321 
328  [SecuritySafeCritical]
329  [__DynamicallyInvokable]
330  public RegionInfo(string name)
331  {
332  if (name == null)
333  {
334  throw new ArgumentNullException("name");
335  }
336  if (name.Length == 0)
337  {
338  throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"));
339  }
340  m_cultureData = CultureData.GetCultureDataForRegion(name, useUserOverride: true);
341  if (m_cultureData == null)
342  {
343  throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidCultureName"), name), "name");
344  }
345  if (m_cultureData.IsNeutralCulture)
346  {
347  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNeutralRegionName", name), "name");
348  }
349  SetName(name);
350  }
351 
356  [SecuritySafeCritical]
357  public RegionInfo(int culture)
358  {
359  switch (culture)
360  {
361  case 127:
362  throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"));
363  case 0:
364  throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
365  case 3072:
366  throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", culture), "culture");
367  }
368  m_cultureData = CultureData.GetCultureData(culture, bUseUserOverride: true);
369  m_name = m_cultureData.SREGIONNAME;
370  if (m_cultureData.IsNeutralCulture)
371  {
372  throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
373  }
374  m_cultureId = culture;
375  }
376 
377  [SecuritySafeCritical]
378  internal RegionInfo(CultureData cultureData)
379  {
380  m_cultureData = cultureData;
381  m_name = m_cultureData.SREGIONNAME;
382  }
383 
384  [SecurityCritical]
385  private void SetName(string name)
386  {
387  m_name = (name.Equals(m_cultureData.SREGIONNAME, StringComparison.OrdinalIgnoreCase) ? m_cultureData.SREGIONNAME : m_cultureData.CultureName);
388  }
389 
390  [SecurityCritical]
391  [OnDeserialized]
392  private void OnDeserialized(StreamingContext ctx)
393  {
394  if (m_name == null)
395  {
396  m_cultureId = IdFromEverettRegionInfoDataItem[m_dataItem];
397  }
398  if (m_cultureId == 0)
399  {
400  m_cultureData = CultureData.GetCultureDataForRegion(m_name, useUserOverride: true);
401  }
402  else
403  {
404  m_cultureData = CultureData.GetCultureData(m_cultureId, bUseUserOverride: true);
405  }
406  if (m_cultureData == null)
407  {
408  throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidCultureName"), m_name), "m_name");
409  }
410  if (m_cultureId == 0)
411  {
412  SetName(m_name);
413  }
414  else
415  {
416  m_name = m_cultureData.SREGIONNAME;
417  }
418  }
419 
420  [OnSerializing]
421  private void OnSerializing(StreamingContext ctx)
422  {
423  }
424 
429  [__DynamicallyInvokable]
430  public override bool Equals(object value)
431  {
432  RegionInfo regionInfo = value as RegionInfo;
433  if (regionInfo != null)
434  {
435  return Name.Equals(regionInfo.Name);
436  }
437  return false;
438  }
439 
442  [__DynamicallyInvokable]
443  public override int GetHashCode()
444  {
445  return Name.GetHashCode();
446  }
447 
450  [__DynamicallyInvokable]
451  public override string ToString()
452  {
453  return Name;
454  }
455  }
456 }
virtual string CurrencySymbol
Gets the currency symbol associated with the country/region.
Definition: RegionInfo.cs:300
RegionInfo(string name)
Initializes a new instance of the T:System.Globalization.RegionInfo class based on the country/region...
Definition: RegionInfo.cs:330
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual string ISOCurrencySymbol
Gets the three-character ISO 4217 currency symbol associated with the country/region.
Definition: RegionInfo.cs:313
virtual string NativeName
Gets the name of a country/region formatted in the native language of the country/region.
Definition: RegionInfo.cs:203
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
virtual string ThreeLetterWindowsRegionName
Gets the three-letter code assigned by Windows to the country/region represented by this T:System....
Definition: RegionInfo.cs:239
Definition: __Canon.cs:3
override int GetHashCode()
Serves as a hash function for the current T:System.Globalization.RegionInfo, suitable for hashing alg...
Definition: RegionInfo.cs:443
virtual int GeoId
Gets a unique identification number for a geographical region, country, city, or location.
Definition: RegionInfo.cs:265
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Contains information about the country/region.
Definition: RegionInfo.cs:11
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
virtual string EnglishName
Gets the full name of the country/region in English.
Definition: RegionInfo.cs:176
override string ToString()
Returns a string containing the culture name or ISO 3166 two-letter country/region codes specified fo...
Definition: RegionInfo.cs:451
static RegionInfo CurrentRegion
Gets the T:System.Globalization.RegionInfo that represents the country/region used by the current thr...
Definition: RegionInfo.cs:144
Format character that affects the layout of text or the operation of text processes,...
virtual string CurrencyEnglishName
Gets the name, in English, of the currency used in the country/region.
Definition: RegionInfo.cs:276
virtual string CurrencyNativeName
Gets the name of the currency used in the country/region, formatted in the native language of the cou...
Definition: RegionInfo.cs:288
override bool Equals(object value)
Determines whether the specified object is the same instance as the current T:System....
Definition: RegionInfo.cs:430
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
The exception that is thrown when one of the arguments provided to a method is not valid.
RegionInfo(int culture)
Initializes a new instance of the T:System.Globalization.RegionInfo class based on the country/region...
Definition: RegionInfo.cs:357
Specifies that the class can be serialized.
virtual string ThreeLetterISORegionName
Gets the three-letter code defined in ISO 3166 for the country/region.
Definition: RegionInfo.cs:228
virtual string DisplayName
Gets the full name of the country/region in the language of the localized version of ....
Definition: RegionInfo.cs:189
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
virtual string TwoLetterISORegionName
Gets the two-letter code defined in ISO 3166 for the country/region.
Definition: RegionInfo.cs:216
virtual bool IsMetric
Gets a value indicating whether the country/region uses the metric system for measurements.
Definition: RegionInfo.cs:252
virtual string Name
Gets the name or ISO 3166 two-letter country/region code for the current T:System....
Definition: RegionInfo.cs:164