1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 ////////////////////////////////////////////////////////////////////////////
9 // Purpose: This class represents settings specified by de jure or
10 // de facto standards for a particular country/region. In
11 // contrast to CultureInfo, the RegionInfo does not represent
12 // preferences of the user and does not depend on the user's
13 // language or culture.
16 ////////////////////////////////////////////////////////////////////////////
18 namespace System.Globalization {
21 using System.Runtime.Serialization;
22 using System.Diagnostics.Contracts;
25 [System.Runtime.InteropServices.ComVisible(true)]
26 public partial class RegionInfo
28 //--------------------------------------------------------------------//
29 // Internal Information //
30 //--------------------------------------------------------------------//
37 // Name of this region (ie: es-US): serialized, the field used for deserialization
39 internal String m_name;
42 // The CultureData instance that we are going to read data from.
44 [NonSerialized]internal CultureData m_cultureData;
47 // The RegionInfo for our current region
49 internal static volatile RegionInfo s_currentRegionInfo;
52 ////////////////////////////////////////////////////////////////////////
54 // RegionInfo Constructors
56 // Note: We prefer that a region be created with a full culture name (ie: en-US)
57 // because otherwise the native strings won't be right.
59 // In Silverlight we enforce that RegionInfos must be created with a full culture name
61 ////////////////////////////////////////////////////////////////////////
62 [System.Security.SecuritySafeCritical] // auto-generated
63 public RegionInfo(String name) {
65 throw new ArgumentNullException("name");
67 if (name.Length == 0) //The InvariantCulture has no matching region
69 throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"), "name");
72 Contract.EndContractBlock();
75 // First try it as an entire culture. We must have user override as true here so
76 // that we can pick up custom cultures *before* built-in ones (if they want to
77 // prefer built-in cultures they will pass "us" instead of "en-US").
79 this.m_cultureData = CultureData.GetCultureDataForRegion(name,true);
80 // this.m_name = name.ToUpper(CultureInfo.InvariantCulture);
82 if (this.m_cultureData == null)
83 throw new ArgumentException(
85 CultureInfo.CurrentCulture,
86 Environment.GetResourceString("Argument_InvalidCultureName"), name), "name");
89 // Not supposed to be neutral
90 if (this.m_cultureData.IsNeutralCulture)
91 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNeutralRegionName", name), "name");
97 // We'd rather people use the named version since this doesn't allow custom locales
98 [System.Security.SecuritySafeCritical] // auto-generated
99 public RegionInfo(int culture)
101 if (culture == CultureInfo.LOCALE_INVARIANT) //The InvariantCulture has no matching region
103 throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"));
106 if (culture == CultureInfo.LOCALE_NEUTRAL)
108 // Not supposed to be neutral
109 throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
112 if (culture == CultureInfo.LOCALE_CUSTOM_DEFAULT)
114 // Not supposed to be neutral
115 throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", culture), "culture");
118 this.m_cultureData = CultureData.GetCultureData(culture,true);
119 this.m_name = this.m_cultureData.SREGIONNAME;
121 if (this.m_cultureData.IsNeutralCulture)
123 // Not supposed to be neutral
124 throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
126 m_cultureId = culture;
130 [System.Security.SecuritySafeCritical] // auto-generated
131 internal RegionInfo(CultureData cultureData)
133 this.m_cultureData = cultureData;
134 this.m_name = this.m_cultureData.SREGIONNAME;
137 [System.Security.SecurityCritical] // auto-generated
138 private void SetName(string name)
141 // Use the name of the region we found
142 this.m_name = this.m_cultureData.SREGIONNAME;
144 // when creating region by culture name, we keep the region name as the culture name so regions
145 // created by custom culture names can be differentiated from built in regions.
146 this.m_name = name.Equals(this.m_cultureData.SREGIONNAME, StringComparison.OrdinalIgnoreCase) ?
147 this.m_cultureData.SREGIONNAME :
148 this.m_cultureData.CultureName;
149 #endif // FEATURE_CORECLR
153 #region Serialization
155 // m_cultureId is needed for serialization only to detect the case if the region info is created using the name or using the LCID.
156 // in case m_cultureId is zero means that the RigionInfo is created using name. otherwise it is created using LCID.
159 [OptionalField(VersionAdded = 2)]
161 // the following field is defined to keep the compatibility with Everett.
162 // don't change/remove the names/types of these field.
163 [OptionalField(VersionAdded = 2)]
164 internal int m_dataItem = 0;
167 static private readonly int[] IdFromEverettRegionInfoDataItem =
169 0x3801, /* 0 */ // AE ar-AE Arabic (U.A.E.)
170 0x041C, /* 1 */ // AL sq-AL Albanian (Albania)
171 0x042B, /* 2 */ // AM hy-AM Armenian (Armenia)
172 0x2C0A, /* 3 */ // AR es-AR Spanish (Argentina)
173 0x0C07, /* 4 */ // AT de-AT German (Austria)
174 0x0C09, /* 5 */ // AU en-AU English (Australia)
175 0x042C, /* 6 */ // AZ az-AZ-Latn Azeri (Latin) (Azerbaijan)
176 // 0x082C, 6, // AZ az-AZ-Cyrl Azeri (Cyrillic) (Azerbaijan)
177 0x080C, /* 7 */ // BE fr-BE French (Belgium)
178 // 0x0813, 7, // BE nl-BE Dutch (Belgium)
179 0x0402, /* 8 */ // BG bg-BG Bulgarian (Bulgaria)
180 0x3C01, /* 9 */ // BH ar-BH Arabic (Bahrain)
181 0x083E, /* 10 */ // BN ms-BN Malay (Brunei Darussalam)
182 0x400A, /* 11 */ // BO es-BO Spanish (Bolivia)
183 0x0416, /* 12 */ // BR pt-BR Portuguese (Brazil)
184 0x0423, /* 13 */ // BY be-BY Belarusian (Belarus)
185 0x2809, /* 14 */ // BZ en-BZ English (Belize)
186 0x0C0C, /* 15 */ // CA fr-CA French (Canada)
187 // 0x1009, 15, // CA en-CA English (Canada)
188 0x2409, /* 16 */ // CB en-CB English (Caribbean)
189 0x0807, /* 17 */ // CH de-CH German (Switzerland)
190 // 0x0810, 17, // CH it-CH Italian (Switzerland)
191 // 0x100C, 17, // CH fr-CH French (Switzerland)
192 0x340A, /* 18 */ // CL es-CL Spanish (Chile)
193 0x0804, /* 19 */ // CN zh-CN Chinese (People's Republic of China)
194 0x240A, /* 20 */ // CO es-CO Spanish (Colombia)
195 0x140A, /* 21 */ // CR es-CR Spanish (Costa Rica)
196 0x0405, /* 22 */ // CZ cs-CZ Czech (Czech Republic)
197 0x0407, /* 23 */ // DE de-DE German (Germany)
198 0x0406, /* 24 */ // DK da-DK Danish (Denmark)
199 0x1C0A, /* 25 */ // DO es-DO Spanish (Dominican Republic)
200 0x1401, /* 26 */ // DZ ar-DZ Arabic (Algeria)
201 0x300A, /* 27 */ // EC es-EC Spanish (Ecuador)
202 0x0425, /* 28 */ // EE et-EE Estonian (Estonia)
203 0x0C01, /* 29 */ // EG ar-EG Arabic (Egypt)
204 0x0403, /* 30 */ // ES ca-ES Catalan (Catalan)
205 // 0x042D, 30, // ES eu-ES Basque (Basque)
206 // 0x0456, 30, // ES gl-ES Galician (Galician)
207 // 0x0C0A, 30, // ES es-ES Spanish (Spain)
208 0x040B, /* 31 */ // FI fi-FI Finnish (Finland)
209 // 0x081D, 31, // FI sv-FI Swedish (Finland)
210 0x0438, /* 32 */ // FO fo-FO Faroese (Faroe Islands)
211 0x040C, /* 33 */ // FR fr-FR French (France)
212 0x0809, /* 34 */ // GB en-GB English (United Kingdom)
213 0x0437, /* 35 */ // GE ka-GE Georgian (Georgia)
214 0x0408, /* 36 */ // GR el-GR Greek (Greece)
215 0x100A, /* 37 */ // GT es-GT Spanish (Guatemala)
216 0x0C04, /* 38 */ // HK zh-HK Chinese (Hong Kong S.A.R.)
217 0x480A, /* 39 */ // HN es-HN Spanish (Honduras)
218 0x041A, /* 40 */ // HR hr-HR Croatian (Croatia)
219 0x040E, /* 41 */ // HU hu-HU Hungarian (Hungary)
220 0x0421, /* 42 */ // ID id-ID Indonesian (Indonesia)
221 0x1809, /* 43 */ // IE en-IE English (Ireland)
222 0x040D, /* 44 */ // IL he-IL Hebrew (Israel)
223 0x0439, /* 45 */ // IN hi-IN Hindi (India)
224 // 0x0446, 45, // IN pa-IN Punjabi (India)
225 // 0x0447, 45, // IN gu-IN Gujarati (India)
226 // 0x0449, 45, // IN ta-IN Tamil (India)
227 // 0x044A, 45, // IN te-IN Telugu (India)
228 // 0x044B, 45, // IN kn-IN Kannada (India)
229 // 0x044E, 45, // IN mr-IN Marathi (India)
230 // 0x044F, 45, // IN sa-IN Sanskrit (India)
231 // 0x0457, 45, // IN kok-IN Konkani (India)
232 0x0801, /* 46 */ // IQ ar-IQ Arabic (Iraq)
233 0x0429, /* 47 */ // IR fa-IR (Iran)
234 0x040F, /* 48 */ // IS is-IS Icelandic (Iceland)
235 0x0410, /* 49 */ // IT it-IT Italian (Italy)
236 0x2009, /* 50 */ // JM en-JM English (Jamaica)
237 0x2C01, /* 51 */ // JO ar-JO Arabic (Jordan)
238 0x0411, /* 52 */ // JP ja-JP Japanese (Japan)
239 0x0441, /* 53 */ // KE sw-KE Swahili (Kenya)
240 0x0440, /* 54 */ // KG ky-KG Kyrgyz (Kyrgyzstan)
241 0x0412, /* 55 */ // KR ko-KR Korean (Korea)
242 0x3401, /* 56 */ // KW ar-KW Arabic (Kuwait)
243 0x043F, /* 57 */ // KZ kk-KZ Kazakh (Kazakhstan)
244 0x3001, /* 58 */ // LB ar-LB Arabic (Lebanon)
245 0x1407, /* 59 */ // LI de-LI German (Liechtenstein)
246 0x0427, /* 60 */ // LT lt-LT Lithuanian (Lithuania)
247 0x1007, /* 61 */ // LU de-LU German (Luxembourg)
248 // 0x140C, 61, // LU fr-LU French (Luxembourg)
249 0x0426, /* 62 */ // LV lv-LV Latvian (Latvia)
250 0x1001, /* 63 */ // LY ar-LY Arabic (Libya)
251 0x1801, /* 64 */ // MA ar-MA Arabic (Morocco)
252 0x180C, /* 65 */ // MC fr-MC French (Principality of Monaco)
253 0x042F, /* 66 */ // MK mk-MK Macedonian (Macedonia, FYRO)
254 0x0450, /* 67 */ // MN mn-MN Mongolian (Mongolia)
255 0x1404, /* 68 */ // MO zh-MO Chinese (Macau S.A.R.)
256 0x0465, /* 69 */ // MV div-MV Divehi (Maldives)
257 0x080A, /* 70 */ // MX es-MX Spanish (Mexico)
258 0x043E, /* 71 */ // MY ms-MY Malay (Malaysia)
259 0x4C0A, /* 72 */ // NI es-NI Spanish (Nicaragua)
260 0x0413, /* 73 */ // NL nl-NL Dutch (Netherlands)
261 0x0414, /* 74 */ // NO nb-NO Norwegian (Bokm?) (Norway)
262 // 0x0814, 74, // NO nn-NO Norwegian (Nynorsk) (Norway)
263 0x1409, /* 75 */ // NZ en-NZ English (New Zealand)
264 0x2001, /* 76 */ // OM ar-OM Arabic (Oman)
265 0x180A, /* 77 */ // PA es-PA Spanish (Panama)
266 0x280A, /* 78 */ // PE es-PE Spanish (Peru)
267 0x3409, /* 79 */ // PH en-PH English (Republic of the Philippines)
268 0x0420, /* 80 */ // PK ur-PK Urdu (Islamic Republic of Pakistan)
269 0x0415, /* 81 */ // PL pl-PL Polish (Poland)
270 0x500A, /* 82 */ // PR es-PR Spanish (Puerto Rico)
271 0x0816, /* 83 */ // PT pt-PT Portuguese (Portugal)
272 0x3C0A, /* 84 */ // PY es-PY Spanish (Paraguay)
273 0x4001, /* 85 */ // QA ar-QA Arabic (Qatar)
274 0x0418, /* 86 */ // RO ro-RO Romanian (Romania)
275 0x0419, /* 87 */ // RU ru-RU Russian (Russia)
276 // 0x0444, 87, // RU tt-RU Tatar (Russia)
277 0x0401, /* 88 */ // SA ar-SA Arabic (Saudi Arabia)
278 0x041D, /* 89 */ // SE sv-SE Swedish (Sweden)
279 0x1004, /* 90 */ // SG zh-SG Chinese (Singapore)
280 0x0424, /* 91 */ // SI sl-SI Slovenian (Slovenia)
281 0x041B, /* 92 */ // SK sk-SK Slovak (Slovakia)
282 0x081A, /* 93 */ // SP sr-SP-Latn Serbian (Latin) (Serbia)
283 // 0x0C1A, 93, // SP sr-SP-Cyrl Serbian (Cyrillic) (Serbia)
284 0x440A, /* 94 */ // SV es-SV Spanish (El Salvador)
285 0x045A, /* 95 */ // SY syr-SY Syriac (Syria)
286 // 0x2801, 95, // SY ar-SY Arabic (Syria)
287 0x041E, /* 96 */ // TH th-TH Thai (Thailand)
288 0x1C01, /* 97 */ // TN ar-TN Arabic (Tunisia)
289 0x041F, /* 98 */ // TR tr-TR Turkish (Turkey)
290 0x2C09, /* 99 */ // TT en-TT English (Trinidad and Tobago)
291 0x0404, /*100 */ // TW zh-TW Chinese (Taiwan)
292 0x0422, /*101 */ // UA uk-UA Ukrainian (Ukraine)
293 0x0409, /*102 */ // US en-US English (United States)
294 0x380A, /*103 */ // UY es-UY Spanish (Uruguay)
295 0x0443, /*104 */ // UZ uz-UZ-Latn Uzbek (Latin) (Uzbekistan)
296 // 0x0843, 104 // UZ uz-UZ-Cyrl Uzbek (Cyrillic) (Uzbekistan)
297 0x200A, /*105*/ // VE es-VE Spanish (Venezuela)
298 0x042A, /*106*/ // VN vi-VN Vietnamese (Viet Nam)
299 0x2401, /*107*/ // YE ar-YE Arabic (Yemen)
300 0x0436, /*108*/ // ZA af-ZA Afrikaans (South Africa)
301 // 0x1C09, 108, // ZA en-ZA English (South Africa)
302 0x3009, /*109*/ // ZW en-ZW English (Zimbabwe)
305 [System.Security.SecurityCritical] // auto-generated
307 private void OnDeserialized(StreamingContext ctx)
310 // This won't happen anyway since CoreCLR doesn't support serialization
311 this.m_cultureData = CultureData.GetCultureData(m_name, true);
315 Contract.Assert(m_dataItem >= 0, "[RegionInfo.OnDeserialized] null name and invalid dataItem");
316 m_cultureId = IdFromEverettRegionInfoDataItem[m_dataItem];
319 if (m_cultureId == 0)
321 this.m_cultureData = CultureData.GetCultureDataForRegion(this.m_name, true);
325 this.m_cultureData = CultureData.GetCultureData(m_cultureId, true);
329 if (this.m_cultureData == null)
330 throw new ArgumentException(
332 CultureInfo.CurrentCulture,
333 Environment.GetResourceString("Argument_InvalidCultureName"), m_name), "m_name");
335 if (m_cultureId == 0)
337 SetName(this.m_name);
341 this.m_name = this.m_cultureData.SREGIONNAME;
346 private void OnSerializing(StreamingContext ctx)
348 // Used to fill in everett data item, unnecessary now
350 #endregion Serialization
352 ////////////////////////////////////////////////////////////////////////
356 // This instance provides methods based on the current user settings.
357 // These settings are volatile and may change over the lifetime of the
360 ////////////////////////////////////////////////////////////////////////
361 public static RegionInfo CurrentRegion {
362 [System.Security.SecuritySafeCritical] // auto-generated
364 RegionInfo temp = s_currentRegionInfo;
367 temp = new RegionInfo(CultureInfo.CurrentCulture.m_cultureData);
369 // Need full name for custom cultures
370 temp.m_name=temp.m_cultureData.SREGIONNAME;
371 s_currentRegionInfo = temp;
377 ////////////////////////////////////////////////////////////////////////
381 // Returns the name of the region (ie: en-US)
383 ////////////////////////////////////////////////////////////////////////
384 public virtual String Name {
386 Contract.Assert(m_name != null, "Expected RegionInfo.m_name to be populated already");
391 ////////////////////////////////////////////////////////////////////////
395 // Returns the name of the region in English. (ie: United States)
397 ////////////////////////////////////////////////////////////////////////
398 public virtual String EnglishName
400 [System.Security.SecuritySafeCritical] // auto-generated
403 return (this.m_cultureData.SENGCOUNTRY);
408 ////////////////////////////////////////////////////////////////////////
412 // Returns the display name (localized) of the region. (ie: United States
413 // if the current UI language is en-US)
415 ////////////////////////////////////////////////////////////////////////
416 public virtual String DisplayName
418 [System.Security.SecuritySafeCritical] // auto-generated
421 return (this.m_cultureData.SLOCALIZEDCOUNTRY);
426 ////////////////////////////////////////////////////////////////////////
430 // Returns the native name of the region. (ie: Deutschland)
431 // WARNING: You need a full locale name for this to make sense.
433 ////////////////////////////////////////////////////////////////////////
434 [System.Runtime.InteropServices.ComVisible(false)]
435 public virtual String NativeName
437 [System.Security.SecuritySafeCritical] // auto-generated
440 return (this.m_cultureData.SNATIVECOUNTRY);
444 ////////////////////////////////////////////////////////////////////////
446 // TwoLetterISORegionName
448 // Returns the two letter ISO region name (ie: US)
450 ////////////////////////////////////////////////////////////////////////
451 public virtual String TwoLetterISORegionName
453 [System.Security.SecuritySafeCritical] // auto-generated
456 return (this.m_cultureData.SISO3166CTRYNAME);
462 ////////////////////////////////////////////////////////////////////////
464 // ThreeLetterISORegionName
466 // Returns the three letter ISO region name (ie: USA)
468 ////////////////////////////////////////////////////////////////////////
469 public virtual String ThreeLetterISORegionName
471 [System.Security.SecuritySafeCritical] // auto-generated
474 return (this.m_cultureData.SISO3166CTRYNAME2);
478 ////////////////////////////////////////////////////////////////////////
480 // ThreeLetterWindowsRegionName
482 // Returns the three letter windows region name (ie: USA)
484 ////////////////////////////////////////////////////////////////////////
485 public virtual String ThreeLetterWindowsRegionName
487 [System.Security.SecuritySafeCritical] // auto-generated
490 return (this.m_cultureData.SABBREVCTRYNAME);
495 ////////////////////////////////////////////////////////////////////////
499 // Returns true if this region uses the metric measurement system
501 ////////////////////////////////////////////////////////////////////////
502 public virtual bool IsMetric {
504 int value = this.m_cultureData.IMEASURE;
510 [System.Runtime.InteropServices.ComVisible(false)]
511 public virtual int GeoId
515 return (this.m_cultureData.IGEOID);
519 ////////////////////////////////////////////////////////////////////////
521 // CurrencyEnglishName
523 // English name for this region's currency, ie: Swiss Franc
525 ////////////////////////////////////////////////////////////////////////
526 [System.Runtime.InteropServices.ComVisible(false)]
527 public virtual String CurrencyEnglishName
529 [System.Security.SecuritySafeCritical] // auto-generated
532 return (this.m_cultureData.SENGLISHCURRENCY);
536 ////////////////////////////////////////////////////////////////////////
538 // CurrencyEnglishName
540 // English name for this region's currency, ie: Schweizer Franken
541 // WARNING: You need a full locale name for this to make sense.
543 ////////////////////////////////////////////////////////////////////////
544 [System.Runtime.InteropServices.ComVisible(false)]
545 public virtual String CurrencyNativeName
547 [System.Security.SecuritySafeCritical] // auto-generated
550 return (this.m_cultureData.SNATIVECURRENCY);
554 ////////////////////////////////////////////////////////////////////////
558 // Currency Symbol for this locale, ie: Fr. or $
560 ////////////////////////////////////////////////////////////////////////
561 public virtual String CurrencySymbol {
562 [System.Security.SecuritySafeCritical] // auto-generated
564 return (this.m_cultureData.SCURRENCY);
568 ////////////////////////////////////////////////////////////////////////
572 // ISO Currency Symbol for this locale, ie: CHF
574 ////////////////////////////////////////////////////////////////////////
575 public virtual String ISOCurrencySymbol {
576 [System.Security.SecuritySafeCritical] // auto-generated
578 return (this.m_cultureData.SINTLSYMBOL);
582 ////////////////////////////////////////////////////////////////////////
586 // Implements Object.Equals(). Returns a boolean indicating whether
587 // or not object refers to the same RegionInfo as the current instance.
589 // RegionInfos are considered equal if and only if they have the same name
592 ////////////////////////////////////////////////////////////////////////
593 public override bool Equals(Object value)
595 RegionInfo that = value as RegionInfo;
598 return this.Name.Equals(that.Name);
604 ////////////////////////////////////////////////////////////////////////
608 // Implements Object.GetHashCode(). Returns the hash code for the
609 // CultureInfo. The hash code is guaranteed to be the same for RegionInfo
610 // A and B where A.Equals(B) is true.
612 ////////////////////////////////////////////////////////////////////////
613 public override int GetHashCode()
615 return (this.Name.GetHashCode());
619 ////////////////////////////////////////////////////////////////////////
623 // Implements Object.ToString(). Returns the name of the Region, ie: es-US
625 ////////////////////////////////////////////////////////////////////////
626 public override String ToString()