コード例 #1
0
        /// <include file='doc\RegionInfo.uex' path='docs/doc[@for="RegionInfo.RegionInfo1"]/*' />
        public RegionInfo(int culture)
        {
            // Get the culture data item.
            int cultureItem = CultureTable.GetDataItemFromCultureID(CultureInfo.GetLangID(culture));

            if (cultureItem < 0)
            {
                // Not a valid culture ID.
                throw new ArgumentException(Environment.GetResourceString("Argument_CultureNotSupported", culture), "culture");
            }

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

            //
            // From this culture data item, get the region data item.
            // We do this because 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).
            //
            m_dataItem = CultureTable.GetDefaultInt32Value(cultureItem, CultureTable.IREGIONITEM);
            if (m_dataItem == 0xffff)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
            }
        }
コード例 #2
0
        internal int culture;               // the culture ID used to create this instance.


        ////////////////////////////////////////////////////////////////////////
        //
        //  CompareInfo Constructor
        //
        //
        ////////////////////////////////////////////////////////////////////////


        // Constructs an instance that most closely corresponds to the NLS locale
        // identifier.
        internal unsafe CompareInfo(GlobalizationAssembly ga, int culture)
        {
            if (culture < 0)
            {
                throw new ArgumentOutOfRangeException("culture", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
            }

            // NOTENOTE YSLin: In the future, move all the culture validation to the native code InitializeCompareInfo, since we make three
            // native calls below, which are expansive.

            //
            // Verify that this is a valid culture.
            //
            int dataItem = CultureTable.GetDataItemFromCultureID(CultureInfo.GetLangID(culture));

            if (dataItem == -1)
            {
                throw new ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_CultureNotSupported"), culture), "culture");
            }

            // We do the following because the native C++ SortingTable is based on the
            // WIN32 LCID.  It doesn't work for neutral cultures liek 0x0009.  So we convert culture
            // to a Win32 LCID here.

            // Note that we have to get Sort ID from culture.  This will affect the result of string comparison.
            this.win32LCID = CultureTable.GetDefaultInt32Value(dataItem, CultureTable.WIN32LANGID);

            int sortID = CultureInfo.GetSortID(culture);

            if (sortID != 0)
            {
                // Need to verify if the Sort ID is valid.
                if (!CultureTable.IsValidSortID(dataItem, sortID))
                {
                    throw new ArgumentException(
                              String.Format(Environment.GetResourceString("Argument_CultureNotSupported"), culture), "culture");
                }
                // This is an alterinative sort LCID.  Hey man, don't forget to take your SORTID with you.
                win32LCID |= sortID << 16;
            }

            // TODO: InitializeCompareInfo should use ga instead of getting the default instance.

            // Call to the native side to create/get the corresponding native C++ SortingTable for this culture.
            // The returned value is a 32-bit pointer to the native C++ SortingTable instance.
            // We cache this pointer so that we can call methods of the SortingTable directly.
            pSortingTable = InitializeCompareInfo(GlobalizationAssembly.m_defaultInstance.pNativeGlobalizationAssembly, win32LCID);
            // Since win32LCID can be different from the passed-in culture in the case of neutral cultures, store the culture ID in a different place.
            this.culture = culture;
        }