< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 50
Coverable lines: 50
Total lines: 195
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%660%
.ctor(...)0%10100%
.ctor(...)100%110%
Equals(...)0%220%
GetHashCode()100%110%
ToString()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Globalization/RegionInfo.cs

#LineLine coverage
 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
 4using System.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace System.Globalization
 8{
 9    /// <summary>
 10    /// This class represents settings specified by de jure or de facto
 11    /// standards for a particular country/region. In contrast to
 12    /// CultureInfo, the RegionInfo does not represent preferences of the
 13    /// user and does not depend on the user's language or culture.
 14    /// </summary>
 15    public class RegionInfo
 16    {
 17        // Name of this region (ie: es-US): serialized, the field used for deserialization
 18        private string _name;
 19
 20        // The CultureData instance that we are going to read data from.
 21        private readonly CultureData _cultureData;
 22
 23        // The RegionInfo for our current region
 24        internal static RegionInfo? s_currentRegionInfo;
 25
 026        public RegionInfo(string name)
 27        {
 028            ArgumentNullException.ThrowIfNull(name);
 29
 30            // The InvariantCulture has no matching region
 031            if (name.Length == 0)
 32            {
 033                throw new ArgumentException(SR.Argument_NoRegionInvariantCulture, nameof(name));
 34            }
 35
 36            // For CoreCLR we only want the region names that are full culture names
 037            _cultureData = CultureData.GetCultureDataForRegion(name, true) ??
 038                throw new ArgumentException(SR.Format(SR.Argument_InvalidCultureName, name), nameof(name));
 39
 40            // Not supposed to be neutral
 041            if (_cultureData.IsNeutralCulture)
 42            {
 043                throw new ArgumentException(SR.Format(SR.Argument_InvalidNeutralRegionName, name), nameof(name));
 44            }
 45
 046            _name = _cultureData.RegionName;
 047        }
 48
 049        public RegionInfo(int culture)
 50        {
 51            // The InvariantCulture has no matching region
 052            if (culture == CultureInfo.LOCALE_INVARIANT)
 53            {
 054                throw new ArgumentException(SR.Argument_NoRegionInvariantCulture);
 55            }
 56
 057            if (culture == CultureInfo.LOCALE_NEUTRAL)
 58            {
 59                // Not supposed to be neutral
 060                throw new ArgumentException(SR.Format(SR.Argument_CultureIsNeutral, culture), nameof(culture));
 61            }
 62
 063            if (culture == CultureInfo.LOCALE_CUSTOM_DEFAULT || culture == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED)
 64            {
 65                // Not supposed to be neutral
 066                throw new ArgumentException(SR.Argument_CustomCultureCannotBePassedByNumber, nameof(culture));
 67            }
 68
 069            _cultureData = CultureData.GetCultureData(culture, true);
 070            _name = _cultureData.RegionName;
 71
 072            if (_cultureData.IsNeutralCulture)
 73            {
 74                // Not supposed to be neutral
 075                throw new ArgumentException(SR.Format(SR.Argument_CultureIsNeutral, culture), nameof(culture));
 76            }
 077        }
 78
 079        internal RegionInfo(CultureData cultureData)
 80        {
 081            _cultureData = cultureData;
 082            _name = _cultureData.RegionName;
 083        }
 84
 85        /// <summary>
 86        /// This instance provides methods based on the current user settings.
 87        /// </summary>
 88        public static RegionInfo CurrentRegion
 89        {
 90            get
 91            {
 092                RegionInfo? temp = s_currentRegionInfo;
 093                if (temp == null)
 94                {
 095                    temp = new RegionInfo(CultureData.GetCurrentRegionData());
 96
 97                    // Need full name for custom cultures
 098                    temp._name = temp._cultureData.RegionName;
 099                    s_currentRegionInfo = temp;
 100                }
 0101                return temp;
 102            }
 103        }
 104
 105        /// <summary>
 106        /// Returns the name of the region (ie: en-US)
 107        /// </summary>
 108        public virtual string Name
 109        {
 110            get
 111            {
 0112                Debug.Assert(_name != null, "Expected RegionInfo._name to be populated already");
 0113                return _name;
 114            }
 115        }
 116
 117        /// <summary>
 118        /// Returns the name of the region in English. (ie: United States)
 119        /// </summary>
 0120        public virtual string EnglishName => _cultureData.EnglishCountryName;
 121
 122        /// <summary>
 123        /// Returns the display name (localized) of the region. (ie: United States
 124        /// if the current UI language is en-US)
 125        /// </summary>
 0126        public virtual string DisplayName => _cultureData.LocalizedCountryName;
 127
 128        /// <summary>
 129        ///  Returns the native name of the region. (ie: Deutschland)
 130        ///  WARNING: You need a full locale name for this to make sense.
 131        /// </summary>
 0132        public virtual string NativeName => _cultureData.NativeCountryName;
 133
 134        /// <summary>
 135        /// Returns the two letter ISO region name (ie: US)
 136        /// </summary>
 0137        public virtual string TwoLetterISORegionName => _cultureData.TwoLetterISOCountryName;
 138
 139        /// <summary>
 140        /// Returns the three letter ISO region name (ie: USA)
 141        /// </summary>
 0142        public virtual string ThreeLetterISORegionName => _cultureData.ThreeLetterISOCountryName;
 143
 144        /// <summary>
 145        /// Returns the three letter windows region name (ie: USA)
 146        /// </summary>
 0147        public virtual string ThreeLetterWindowsRegionName => ThreeLetterISORegionName;
 148
 149
 150        /// <summary>
 151        /// Returns true if this region uses the metric measurement system
 152        /// </summary>
 0153        public virtual bool IsMetric => _cultureData.MeasurementSystem == 0;
 154
 0155        public virtual int GeoId => _cultureData.GeoId;
 156
 157        /// <summary>
 158        /// English name for this region's currency, ie: Swiss Franc
 159        /// </summary>
 0160        public virtual string CurrencyEnglishName => _cultureData.CurrencyEnglishName;
 161
 162        /// <summary>
 163        /// Native name for this region's currency, ie: Schweizer Franken
 164        /// WARNING: You need a full locale name for this to make sense.
 165        /// </summary>
 0166        public virtual string CurrencyNativeName => _cultureData.CurrencyNativeName;
 167
 168        /// <summary>
 169        /// Currency Symbol for this locale, ie: Fr. or $
 170        /// </summary>
 0171        public virtual string CurrencySymbol => _cultureData.CurrencySymbol;
 172
 173        /// <summary>
 174        /// ISO Currency Symbol for this locale, ie: CHF
 175        /// </summary>
 0176        public virtual string ISOCurrencySymbol => _cultureData.ISOCurrencySymbol;
 177
 178        /// <summary>
 179        /// Implements Object.Equals().  Returns a boolean indicating whether
 180        /// or not object refers to the same RegionInfo as the current instance.
 181        /// RegionInfos are considered equal if and only if they have the same name
 182        /// (ie: en-US)
 183        /// </summary>
 184        public override bool Equals([NotNullWhen(true)] object? value)
 185        {
 0186            return value is RegionInfo otherRegion
 0187                && Name.Equals(otherRegion.Name);
 188        }
 189
 0190        public override int GetHashCode() => Name.GetHashCode();
 191
 0192        public override string ToString() => Name;
 193    }
 194}
 195