Exemple #1
0
 private void OnDeserialized(StreamingContext ctx)
 {
     if ((this.m_name != null) && (this.cultureID != 0x40a))
     {
         this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(this.m_name, this.m_useUserOverride);
     }
     else
     {
         this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(this.cultureID, this.m_useUserOverride);
     }
     this.m_isInherited = base.GetType() != typeof(CultureInfo);
     if (this.m_name == null)
     {
         this.m_name = this.m_cultureTableRecord.ActualName;
     }
     if (base.GetType().Assembly == typeof(CultureInfo).Assembly)
     {
         if (this.textInfo != null)
         {
             CheckDomainSafetyObject(this.textInfo, this);
         }
         if (this.compareInfo != null)
         {
             CheckDomainSafetyObject(this.compareInfo, this);
         }
     }
 }
        ////////////////////////////////////////////////////////////////////////
        //
        //  RegionInfo Constructors
        //
        ////////////////////////////////////////////////////////////////////////


        public RegionInfo(String name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidRegionName", name), "name");
            }
            this.m_name = name.ToUpper(CultureInfo.InvariantCulture);

            m_cultureId = 0;

            //
            // 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_cultureTableRecord = CultureTableRecord.GetCultureTableRecordForRegion(name, true);

            if (this.m_cultureTableRecord.IsNeutralCulture)
            {
                // Not supposed to be neutral
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNeutralRegionName", name), "name");
            }
        }
Exemple #3
0
        // We aren't persisting dataItem any more (since its useless & we weren't using it),
        // Ditto with m_useUserOverride.  Don't use them, we use a local copy of everything.
        internal NumberFormatInfo(CultureTableRecord cultureTableRecord)
        {
            if (cultureTableRecord != null)
            {
                /*
                 * We don't have information for the following four.  All cultures use
                 * the same value set in the ctor of NumberFormatInfo.
                 * PercentGroupSize
                 * PercentDecimalDigits
                 * PercentGroupSeparator
                 * PerMilleSymbol
                 */

                // We directly use fields here since these data is coming from data table or Win32, so we
                // don't need to verify their values (except for invalid parsing situations).

                cultureTableRecord.GetNFIOverrideValues(this);

                if ((932 == cultureTableRecord.IDEFAULTANSICODEPAGE) ||
                    (949 == cultureTableRecord.IDEFAULTANSICODEPAGE))
                {
                    // Legacy behavior for cultures that use Japaanese/Korean default ANSI code pages
                    this.ansiCurrencySymbol = "\\";
                }
                this.negativeInfinitySymbol = cultureTableRecord.SNEGINFINITY;
                this.positiveInfinitySymbol = cultureTableRecord.SPOSINFINITY;
                this.nanSymbol = cultureTableRecord.SNAN;
            }
        }
Exemple #4
0
        private unsafe void OnDeserialized()
        {
            // this method will be called twice because of the support of IDeserializationCallback
            if (m_cultureTableRecord == null)
            {
                if (m_win32LangID == 0)
                {
                    m_win32LangID = CultureTableRecord.IdFromEverettDataItem(m_nDataItem);
                }

                if (customCultureName != null)
                {
                    m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(customCultureName, m_useUserOverride);
                }
                else
                {
                    m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(m_win32LangID, m_useUserOverride);
                }

                m_textInfoID = m_cultureTableRecord.ITEXTINFO;

                if (m_cultureTableRecord.IsSynthetic)
                {
                    // <SyntheticSupport/>
                    m_pNativeTextInfo = InvariantNativeTextInfo;
                }
                else
                {
                    m_pNativeTextInfo = GetNativeTextInfo(m_textInfoID);
                }
            }
        }
Exemple #5
0
 public void ClearCachedData()
 {
     m_userDefaultUICulture         = null;
     m_userDefaultCulture           = null;
     RegionInfo.m_currentRegionInfo = null;
     TimeZone.ResetTimeZone();
     m_LcidCachedCultures = null;
     m_NameCachedCultures = null;
     CultureTableRecord.ResetCustomCulturesCache();
     System.Globalization.CompareInfo.ClearDefaultAssemblyCache();
 }
Exemple #6
0
 public CultureInfo(string name, bool useUserOverride)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_String"));
     }
     this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(name, useUserOverride);
     this.cultureID            = this.m_cultureTableRecord.ActualCultureID;
     this.m_name        = this.m_cultureTableRecord.ActualName;
     this.m_isInherited = base.GetType() != typeof(CultureInfo);
 }
Exemple #7
0
        internal CultureInfo(string cultureName, string textAndCompareCultureName)
        {
            if (cultureName == null)
            {
                throw new ArgumentNullException("cultureName", Environment.GetResourceString("ArgumentNull_String"));
            }
            this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(cultureName, false);
            this.cultureID            = this.m_cultureTableRecord.ActualCultureID;
            this.m_name = this.m_cultureTableRecord.ActualName;
            CultureInfo cultureInfo = GetCultureInfo(textAndCompareCultureName);

            this.compareInfo = cultureInfo.CompareInfo;
            this.textInfo    = cultureInfo.TextInfo;
        }
Exemple #8
0
        //
        // IsValidLcid
        // Lcid is valid if it is built in lcid or synthetic one.
        //

        private static bool IsValidLcid(int lcid, bool canBeCustomLcid)
        {
            if (canBeCustomLcid && CultureTableRecord.IsCustomCultureId(lcid))
            {
                return(true);
            }

            if (CultureTable.Default.IsExistingCulture(lcid))
            {
                return(true);
            }


            return(false);
        }
Exemple #9
0
        private void OnSerializing(StreamingContext ctx)
        {
            m_nDataItem       = m_cultureTableRecord.EverettDataItem();
            m_useUserOverride = m_cultureTableRecord.UseUserOverride;

            if (CultureTableRecord.IsCustomCultureId(m_cultureTableRecord.CultureID))
            {
                customCultureName = m_cultureTableRecord.SNAME;
                m_win32LangID     = m_textInfoID;
            }
            else
            {
                customCultureName = null;
                m_win32LangID     = m_cultureTableRecord.CultureID;
            }
        }
 private void OnDeserialized(StreamingContext ctx)
 {
     if (m_name == null)
     {
         BCLDebug.Assert(m_dataItem >= 0, "[RegionInfo.OnDeserialized] null name and invalid dataItem");
         m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(CultureTableRecord.IdFromEverettRegionInfoDataItem(m_dataItem), true);
         m_name = m_cultureTableRecord.SREGIONNAME;
     }
     else
     {
         if (m_cultureId != 0)
         {
             m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(m_cultureId, true);
         }
         else
         {
             m_cultureTableRecord = CultureTableRecord.GetCultureTableRecordForRegion(m_name, true);
         }
     }
 }
Exemple #11
0
 public CultureInfo(int culture, bool useUserOverride)
 {
     if (culture < 0)
     {
         throw new ArgumentOutOfRangeException("culture", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
     }
     switch (culture)
     {
     case 0x800:
     case 0xc00:
     case 0x1000:
     case 0:
     case 0x400:
         throw new ArgumentException(Environment.GetResourceString("Argument_CultureNotSupported", new object[] { culture }), "culture");
     }
     this.cultureID            = culture;
     this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(this.cultureID, useUserOverride);
     this.m_name        = this.m_cultureTableRecord.ActualName;
     this.m_isInherited = base.GetType() != typeof(CultureInfo);
 }
Exemple #12
0
        ////////////////////////////////////////////////////////////////////////
        //
        //  TextInfo Constructors
        //
        //  Implements CultureInfo.TextInfo.
        //
        ////////////////////////////////////////////////////////////////////////
        internal unsafe TextInfo(CultureTableRecord table)
        {
            this.m_cultureTableRecord = table;
            this.m_textInfoID         = this.m_cultureTableRecord.ITEXTINFO;

            if (table.IsSynthetic)
            {
                // <SyntheticSupport/>
                //
                // we just initialize m_pNativeTextInfo with variant to make the synthetic TextInfo works when
                // GetCaseInsensitiveHashCode and ChangeCaseSurrogate get called. otherwise m_pNativeTextInfo
                // is not used at all in TextInfo with synthetic cultures.
                //
                m_pNativeTextInfo = InvariantNativeTextInfo;
            }
            else
            {
                this.m_pNativeTextInfo = GetNativeTextInfo(this.m_textInfoID);
            }
        }
        public RegionInfo(int culture)
        {
            // Get the culture data item.

            if (culture == CultureInfo.LOCALE_INVARIANT)   //The InvariantCulture has no matching region
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"));
            }

            if (CultureTableRecord.IsCustomCultureId(culture))   // Customized culture
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", "culture"));
            }
            if (CultureInfo.GetSubLangID(culture) == 0)
            {
                // Supposed to have sublang (region) info
                throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
            }

            //
            // From this region data item, get the region data item.
            // Several culture ID may map to the same region.
            // For example, 0x1009 (English (Canada)) and 0x0c0c (French (Canada)) all map to
            // the same region "CA" (Canada).
            //
            this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(culture, true);

            if (this.m_cultureTableRecord.IsNeutralCulture)
            {
                // Not supposed to be neutral
                throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
            }

            // Make sure that we initialize m_name since it will be used in deserialization.
            this.m_name = this.m_cultureTableRecord.SREGIONNAME;

            m_cultureId = culture;
        }
 internal RegionInfo(CultureTableRecord table)
 {
     this.m_cultureTableRecord = table;
     // Make sure that we initialize m_name since it will be used in deserialization.
     this.m_name = this.m_cultureTableRecord.SREGIONNAME;
 }
Exemple #15
0
        internal static CultureInfo GetCultureInfoHelper(int lcid, string name, string altName)
        {
            CultureInfo info;
            Hashtable   nameCachedCultures = m_NameCachedCultures;

            if (name != null)
            {
                name = CultureTableRecord.AnsiToLower(name);
            }
            if (altName != null)
            {
                altName = CultureTableRecord.AnsiToLower(altName);
            }
            if (nameCachedCultures == null)
            {
                nameCachedCultures = Hashtable.Synchronized(new Hashtable());
            }
            else if (lcid == -1)
            {
                info = (CultureInfo)nameCachedCultures[name + ((char)0xfffd) + altName];
                if (info != null)
                {
                    return(info);
                }
            }
            else if (lcid == 0)
            {
                info = (CultureInfo)nameCachedCultures[name];
                if (info != null)
                {
                    return(info);
                }
            }
            Hashtable lcidCachedCultures = m_LcidCachedCultures;

            if (lcidCachedCultures == null)
            {
                lcidCachedCultures = Hashtable.Synchronized(new Hashtable());
            }
            else if (lcid > 0)
            {
                info = (CultureInfo)lcidCachedCultures[lcid];
                if (info != null)
                {
                    return(info);
                }
            }
            try
            {
                switch (lcid)
                {
                case -1:
                    info = new CultureInfo(name, altName);
                    goto Label_010A;

                case 0:
                    info = new CultureInfo(name, false);
                    goto Label_010A;
                }
                if ((m_userDefaultCulture != null) && (m_userDefaultCulture.LCID == lcid))
                {
                    info = (CultureInfo)m_userDefaultCulture.Clone();
                    info.m_cultureTableRecord = info.m_cultureTableRecord.CloneWithUserOverride(false);
                }
                else
                {
                    info = new CultureInfo(lcid, false);
                }
            }
            catch (ArgumentException)
            {
                return(null);
            }
Label_010A:
            info.m_isReadOnly = true;
            if (lcid == -1)
            {
                nameCachedCultures[name + ((char)0xfffd) + altName] = info;
                info.TextInfo.SetReadOnlyState(true);
            }
            else
            {
                if (!CultureTable.IsNewNeutralChineseCulture(info))
                {
                    lcidCachedCultures[info.LCID] = info;
                }
                string str = CultureTableRecord.AnsiToLower(info.m_name);
                nameCachedCultures[str] = info;
            }
            if (-1 != lcid)
            {
                m_LcidCachedCultures = lcidCachedCultures;
            }
            m_NameCachedCultures = nameCachedCultures;
            return(info);
        }
Exemple #16
0
 private void OnDeserializing(StreamingContext ctx)
 {
     m_cultureTableRecord = null;
     m_win32LangID        = 0;
 }