private void OnDeserialized(StreamingContext ctx)
        {
            // In .NET ver 1.0 we can get m_name = null if the Name property never requested 
            // before serializing the culture info object.

            BCLDebug.Assert(m_name != null || cultureID>0,  "[CultureInfo.OnDeserialized] m_name != null || cultureID>0");

            if (m_name != null && cultureID != LOCALE_TRADITIONAL_SPANISH)
                m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(m_name, m_useUserOverride);
            else
                m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(cultureID, m_useUserOverride);

            m_isInherited = (this.GetType() != typeof(System.Globalization.CultureInfo));

            if (m_name == null)
            {
                m_name = m_cultureTableRecord.ActualName;
            }

            // in case we have non customized CultureInfo object we shouldn't allow any customized object  
            // to be attached to it for cross app domain safety.
            if (this.GetType().Assembly == typeof(System.Globalization.CultureInfo).Assembly)
            {
                if (textInfo != null)
                {
                    CheckDomainSafetyObject(textInfo, this);
                }
                
                if (compareInfo != null)
                {
                    CheckDomainSafetyObject(compareInfo, this);
                }
            }
        }
        //
        // GetCultureTableRecordForRegion create CultureTableRecord object for specific region name.
        // this method do the following
        //  o   try to get the object from the cache. if found then return otherwise try to create it.
        //  o   it try to get the record from the framework culture table. if found it then create 
        //      the CultureTableRecord object and store it in the cache then return.
        //  o   call GetCultureTableRecord to get the object. if found it then store it in the cache 
        //      and return. notice that GetCultureTableRecord will try the custom culture then synthetic
        //      culture.
        //  o   otherwise we'll throw ArgumentException.
        //
        
        internal static CultureTableRecord GetCultureTableRecordForRegion(string regionName, bool useUserOverride)
        {
            BCLDebug.Assert(regionName != null, "[CultureTableRecord::GetCultureTableRecordForRegion] regionName should be valid.");
            
            // Make sure the cache is valid.
            if (CultureTableRecordRegionCache == null)
            {
                lock (InternalSyncObject)
                {
                    if (CultureTableRecordRegionCache == null)
                        CultureTableRecordRegionCache = new Hashtable();
                }
            }
            
            regionName = ValidateCulturePieceToLower(regionName, "regionName", MAXSIZE_FULLTAGNAME);
            
            CultureTableRecord [] cultureRecordArray = (CultureTableRecord []) CultureTableRecordRegionCache[regionName];
            if (cultureRecordArray != null)
            {
                int index = useUserOverride ? 0 : 1;
                if (cultureRecordArray[index] == null)
                {
                    cultureRecordArray[index] = cultureRecordArray[index == 0 ? 1 : 0].CloneWithUserOverride(useUserOverride);
                }
                return cultureRecordArray[index];
            }

            int dataItem = CultureTable.Default.GetDataItemFromRegionName(regionName);

            CultureTableRecord cultureRecord = null;
            
            if (dataItem > 0)
            {
                cultureRecord = new CultureTableRecord(regionName, dataItem, useUserOverride);
            }
            else
            {
                try 
                {
                    cultureRecord = GetCultureTableRecord(regionName, useUserOverride);
                } 
                catch (ArgumentException)
                {
                    throw new ArgumentException(
                                String.Format(
                                    CultureInfo.CurrentCulture,
                                    Environment.GetResourceString("Argument_InvalidRegionName"), regionName), "name");
                }
            }

            BCLDebug.Assert(cultureRecord != null, "[CultureTableRecord::GetCultureTableRecordForRegion] cultureRecord should be valid.");
            lock (InternalSyncObject)
            {
                if (CultureTableRecordRegionCache[regionName] == null)
                {
                    cultureRecordArray = new CultureTableRecord[2];
                    cultureRecordArray[useUserOverride ? 0 : 1] = cultureRecord.CloneWithUserOverride(useUserOverride);
                    CultureTableRecordRegionCache[regionName] = cultureRecordArray;
                }
            }

            return cultureRecord;
        }
        public unsafe CultureInfo(int culture, bool useUserOverride) {
            // We don't check for other invalid LCIDS here...
            if (culture < 0) {
                throw new ArgumentOutOfRangeException("culture",
                    Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
            }

            switch (culture)
            {
                case LOCALE_CUSTOM_DEFAULT:
                    // CONSDIER: Support this LCID value any time the OS is using a custom culture as the user default.
                    //           Note that if this is to be supported that the code below is not correct since it assumes
                    //           the LCID value is describing the NLS+ culture, not the NLS locale.
/*
                    this.m_cultureTableRecord = CultureInfo.CurrentCulture.m_cultureTableRecord;
                    this.cultureID = CultureInfo.CurrentCulture.cultureID;
                    break;
*/
                case LOCALE_SYSTEM_DEFAULT:
/*
                    String strSystemDefault = nativeGetUserDefaultLCID(&culture, LOCALE_SYSTEM_DEFAULT);
                    CultureInfo systemDefault;

                    // See if we can get our LOCALE_SYSTEM_DEFAULT
                    systemDefault = GetCultureByLCIDOrName(culture, strSystemDefault);

                    if (systemDefault == null)
                        //                                                 
                        systemDefault = InvariantCulture;

                    this.cultureID = systemDefault.cultureID;
                    this.m_cultureTableRecord = systemDefault.m_cultureTableRecord;
                    break;
*/
                case LOCALE_NEUTRAL:
                case LOCALE_USER_DEFAULT:
                case LOCALE_CUSTOM_UNSPECIFIED:
                    // Can't support unknown custom cultures and we do not support neutral or
                    // non-custom user locales.
                    throw new ArgumentException(
                        Environment.GetResourceString("Argument_CultureNotSupported", culture), "culture");
                default:
                    this.cultureID = culture;
                    // Now see if this LCID is supported in the system default culture.nlp table.
                    this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(this.cultureID, useUserOverride);
                    this.m_name = this.m_cultureTableRecord.ActualName;
                    break;
            }
            m_isInherited = (this.GetType() != typeof(System.Globalization.CultureInfo));
        }
 private void OnDeserializing(StreamingContext ctx) 
 { 
     m_cultureTableRecord = null;
     m_win32LangID        = 0;
 }   
 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 #6
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);
         }
     }
 }
        // 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;
            }
        }
        private void OnDeserialized(StreamingContext ctx)
        {
            BCLDebug.Assert(CultureID >= 0, "[DateTimeFormatInfo.OnDeserialized] clulture ID < 0");

            if (CultureTableRecord.IsCustomCultureId(CultureID))
                m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(m_name, m_useUserOverride);
            else
                m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(CultureID, m_useUserOverride);
            
            if (calendar == null)
            {
                calendar = (Calendar) GregorianCalendar.GetDefaultInstance().Clone();
                calendar.SetReadOnlyState(m_isReadOnly);
            }
            else
            {
                CultureInfo.CheckDomainSafetyObject(calendar, this);
            }

            InitializeOverridableProperties();
        }
 private void OnDeserialized(StreamingContext ctx)
 {
     if (CultureTableRecord.IsCustomCultureId(this.CultureID))
     {
         this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(this.m_name, this.m_useUserOverride);
     }
     else
     {
         this.m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(this.CultureID, this.m_useUserOverride);
     }
     if (this.calendar == null)
     {
         this.calendar = (System.Globalization.Calendar) GregorianCalendar.GetDefaultInstance().Clone();
         this.calendar.SetReadOnlyState(this.m_isReadOnly);
     }
     else
     {
         CultureInfo.CheckDomainSafetyObject(this.calendar, this);
     }
     this.InitializeOverridableProperties();
 }
        public DateTimeFormatInfo() {
            //
            // Invariant DateTimeFormatInfo doesn't have user-overriden values, so we pass false in useUserOverride.
            //
            this.m_cultureTableRecord = CultureInfo.InvariantCulture.m_cultureTableRecord;
            // In Invariant culture, the default calendar store in culture.nlp is Gregorian localized.
            // And the date/time pattern for invariant culture stored in
            this.m_isDefaultCalendar = true;
            this.calendar = GregorianCalendar.GetDefaultInstance();

            // We don't have to call the setter of Calendar property here because the Calendar getter
            // will return Gregorian localized calendar by default.
            InitializeOverridableProperties();
        }
 internal DateTimeFormatInfo(CultureTableRecord cultureTable, int cultureID, Calendar cal) {
     this.m_cultureTableRecord = cultureTable;
     // m_isDefaultCalendar is set in the setter of Calendar below.
     this.Calendar = cal;
 }
        //
        // GetCalendarNativeNameFallback is used when we got empty string native calendar name from the culture data
        // in the case of the custom cultures. 
        // GetCalendarNativeNameFallback is getting the name from the framework data from some specific cultures
        // for example to get the native name for Hijri calendar we use ar-SA culture to get that name.
        //
        private string GetCalendarNativeNameFallback(int calendarId)
        {
            BCLDebug.Assert(calendarId != Calendar.CAL_GREGORIAN, 
                        "[DateTimeFormatInfo.GetCalendarNativeNameFallback] Unexpected Gregorian localized calendar.");
            
            if (m_calendarNativeNames == null)
            {
                lock (InternalSyncObject)
                {
                    if (m_calendarNativeNames == null)
                        m_calendarNativeNames = new Hashtable();
                }
            }

            BCLDebug.Assert(m_calendarNativeNames != null, 
                        "[DateTimeFormatInfo.GetCalendarNativeNameFallback] m_calendarNativeNames should be valid");

            string temp = (string) m_calendarNativeNames[calendarId];
            if (temp != null)
                return temp;

            string name = String.Empty;

            int cultureId = CalendarIdToCultureId(calendarId);

            if (cultureId != 0)
            {
                String [] values = new CultureTableRecord(cultureId, false).SNATIVECALNAMES;

                BCLDebug.Assert(calendar.ID >= 1, "[DateTimeFormatInfo.GetCalendarNativeNameFallback] calendar.ID >= 1");

                int id = calendar.ID - 1;

                // The element 0 stored the name for calendar ID 1 (since there is no calendar ID 0)
                if (id < values.Length)
                {
                    // If U+FEFF is stored, it means that no information for that calendar is available.
                    if (values[id].Length > 0 && values[id][0] != '\xfeff')
                        name = values[id];
                }
            }

            lock (InternalSyncObject)
            {
                if (m_calendarNativeNames[calendarId] == null)
                    m_calendarNativeNames[calendarId] = name;
            }
            
            return name;
        }
        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;
        }
        ////////////////////////////////////////////////////////////////////////
        //
        //  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 #15
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);
 }
 public DateTimeFormatInfo()
 {
     this.firstDayOfWeek = -1;
     this.calendarWeekRule = -1;
     this.formatFlags = ~DateTimeFormatFlags.None;
     this.m_cultureTableRecord = CultureInfo.InvariantCulture.m_cultureTableRecord;
     this.m_isDefaultCalendar = true;
     this.calendar = GregorianCalendar.GetDefaultInstance();
     this.InitializeOverridableProperties();
 }
Exemple #17
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;
 }
 internal DateTimeFormatInfo(CultureTableRecord cultureTable, int cultureID, System.Globalization.Calendar cal)
 {
     this.firstDayOfWeek = -1;
     this.calendarWeekRule = -1;
     this.formatFlags = ~DateTimeFormatFlags.None;
     this.m_cultureTableRecord = cultureTable;
     this.Calendar = cal;
 }
Exemple #19
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);
 }
 private string GetCalendarNativeNameFallback(int calendarId)
 {
     if (m_calendarNativeNames == null)
     {
         lock (InternalSyncObject)
         {
             if (m_calendarNativeNames == null)
             {
                 m_calendarNativeNames = new Hashtable();
             }
         }
     }
     string str = (string) m_calendarNativeNames[calendarId];
     if (str != null)
     {
         return str;
     }
     string str2 = string.Empty;
     int cultureId = CalendarIdToCultureId(calendarId);
     if (cultureId != 0)
     {
         string[] sNATIVECALNAMES = new CultureTableRecord(cultureId, false).SNATIVECALNAMES;
         int index = this.calendar.ID - 1;
         if (((index < sNATIVECALNAMES.Length) && (sNATIVECALNAMES[index].Length > 0)) && (sNATIVECALNAMES[index][0] != 0xfeff))
         {
             str2 = sNATIVECALNAMES[index];
         }
     }
     lock (InternalSyncObject)
     {
         if (m_calendarNativeNames[calendarId] == null)
         {
             m_calendarNativeNames[calendarId] = str2;
         }
     }
     return str2;
 }
        ////////////////////////////////////////////////////////////////////////
        //
        //  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);
            }
        }
        //
        // GetCultureTableRecord create CultureTableRecord object for specific culture name.
        // This method uses CultureTableRecordCache to make sure we don't have to create this
        // object if it is already created before.
        //

        internal static CultureTableRecord GetCultureTableRecord(string name, bool useUserOverride)
        {
            BCLDebug.Assert(name != null, "[CultureTableRecord::GetCultureTableRecord] name should be valid.");
        
            // Make sure the cache is valid.
            if (CultureTableRecordCache == null)
            {
                if (name.Length == 0) // Invariant culture
                {
                    // First time Invariant culture get created we ignore creating the cache
                    return new CultureTableRecord(name, useUserOverride);
                }
                
                lock (InternalSyncObject)
                {
                    if (CultureTableRecordCache == null)
                        CultureTableRecordCache = new Hashtable();
                }
            }

            name = ValidateCulturePieceToLower(name, "name", MAXSIZE_FULLTAGNAME);

            CultureTableRecord [] cultureRecordArray = (CultureTableRecord []) CultureTableRecordCache[name];
            if (cultureRecordArray != null)
            {
                int index   = useUserOverride ? 0 : 1;

                if (cultureRecordArray[index] == null)
                {
                    int filled  = index == 0 ? 1 : 0;
                    cultureRecordArray[index] = (CultureTableRecord) cultureRecordArray[filled].CloneWithUserOverride(useUserOverride);
                }

                return cultureRecordArray[index];
            }

            CultureTableRecord cultureRecord = new CultureTableRecord(name, useUserOverride);
            lock (InternalSyncObject)
            {
                if (CultureTableRecordCache[name] == null)
                {
                    cultureRecordArray = new CultureTableRecord[2];
                    cultureRecordArray[useUserOverride ? 0 : 1] = cultureRecord;
                    CultureTableRecordCache[name] = cultureRecordArray;
                }
            }

            return cultureRecord;
        }
        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);                         
                }
            }
        }
 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;            
 }