Пример #1
0
        public RegionInfo(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            // The InvariantCulture has no matching region
            if (name.Length == 0)
            {
                throw new ArgumentException(SR.Argument_NoRegionInvariantCulture, nameof(name));
            }

            // For CoreCLR we only want the region names that are full culture names
            _cultureData = CultureData.GetCultureDataForRegion(name, true) ??
                           throw new ArgumentException(SR.Format(SR.Argument_InvalidCultureName, name), nameof(name));

            // Not supposed to be neutral
            if (_cultureData.IsNeutralCulture)
            {
                throw new ArgumentException(SR.Format(SR.Argument_InvalidNeutralRegionName, name), nameof(name));
            }

            _name = _cultureData.RegionName;
        }
Пример #2
0
        ////////////////////////////////////////////////////////////////////////
        //
        //  RegionInfo Constructors
        //
        //  Note: We prefer that a region be created with a full culture name (ie: en-US)
        //  because otherwise the native strings won't be right.
        //
        //  In Silverlight we enforce that RegionInfos must be created with a full culture name
        //
        ////////////////////////////////////////////////////////////////////////
        public RegionInfo(String name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (name.Length == 0) //The InvariantCulture has no matching region
            {
                throw new ArgumentException(SR.Argument_NoRegionInvariantCulture, nameof(name));
            }

            Contract.EndContractBlock();

            //
            // For CoreCLR we only want the region names that are full culture names
            //
            _cultureData = CultureData.GetCultureDataForRegion(name, true);
            if (_cultureData == null)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              SR.Argument_InvalidCultureName, name), nameof(name));
            }


            // Not supposed to be neutral
            if (_cultureData.IsNeutralCulture)
            {
                throw new ArgumentException(SR.Format(SR.Argument_InvalidNeutralRegionName, name), nameof(name));
            }

            SetName(name);
        }
 private void OnDeserialized(StreamingContext ctx)
 {
     if (this.m_name == null)
     {
         this.m_cultureId = IdFromEverettRegionInfoDataItem[this.m_dataItem];
     }
     if (this.m_cultureId == 0)
     {
         this.m_cultureData = CultureData.GetCultureDataForRegion(this.m_name, true);
     }
     else
     {
         this.m_cultureData = CultureData.GetCultureData(this.m_cultureId, true);
     }
     if (this.m_cultureData == null)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidCultureName"), new object[] { this.m_name }), "m_name");
     }
     if (this.m_cultureId == 0)
     {
         this.SetName(this.m_name);
     }
     else
     {
         this.m_name = this.m_cultureData.SREGIONNAME;
     }
 }
Пример #4
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public RegionInfo(String name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Length == 0) //The InvariantCulture has no matching region
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"));
            }

            Contract.EndContractBlock();

#if FEATURE_CORECLR
            //
            // For CoreCLR we only want the region names that are full culture names
            //
            this.m_cultureData = CultureData.GetCultureData(name, true);
#else
            //
            // First try it as an entire culture. We must have user override as true here so
            // that we can pick up custom cultures *before* built-in ones (if they want to
            // prefer built-in cultures they will pass "us" instead of "en-US").
            //
            this.m_cultureData = CultureData.GetCultureDataForRegion(name, true);
            // this.m_name = name.ToUpper(CultureInfo.InvariantCulture);
#endif // FEATURE_CORECLR
            if (this.m_cultureData == null)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Environment.GetResourceString("Argument_InvalidCultureName"), name), "name");
            }


            // Not supposed to be neutral
            if (this.m_cultureData.IsNeutralCulture)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNeutralRegionName", name), "name");
            }

            SetName(name);
        }
Пример #5
0
 public RegionInfo(string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"));
     }
     this.m_cultureData = CultureData.GetCultureDataForRegion(name, true);
     if (this.m_cultureData == null)
     {
         throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidCultureName"), (object)name), "name");
     }
     if (this.m_cultureData.IsNeutralCulture)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNeutralRegionName", (object)name), "name");
     }
     this.SetName(name);
 }
Пример #6
0
        private void OnDeserialized(StreamingContext ctx)
        {
#if FEATURE_CORECLR
            // This won't happen anyway since CoreCLR doesn't support serialization
            this.m_cultureData = CultureData.GetCultureData(m_name, true);
#else
            if (m_name == null)
            {
                Contract.Assert(m_dataItem >= 0, "[RegionInfo.OnDeserialized] null name and invalid dataItem");
                m_cultureId = IdFromEverettRegionInfoDataItem[m_dataItem];
            }

            if (m_cultureId == 0)
            {
                this.m_cultureData = CultureData.GetCultureDataForRegion(this.m_name, true);
            }
            else
            {
                this.m_cultureData = CultureData.GetCultureData(m_cultureId, true);
            }
#endif
            //
            if (this.m_cultureData == null)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Environment.GetResourceString("Argument_InvalidCultureName"), m_name), "m_name");
            }

            if (m_cultureId == 0)
            {
                SetName(this.m_name);
            }
            else
            {
                this.m_name = this.m_cultureData.SREGIONNAME;
            }
        }