System.Globalization.CompareInfo.GetCompareInfo C# (CSharp) Method

GetCompareInfo() public static method

public static GetCompareInfo ( int culture, Assembly assembly ) : CompareInfo
culture int
assembly Assembly
return CompareInfo
        public static CompareInfo GetCompareInfo(int culture, Assembly assembly) {
            // Parameter checking.
            if (assembly == null) {
                throw new ArgumentNullException("assembly");
            }

            if (CultureTableRecord.IsCustomCultureId(culture))
            {
                // Customized culture cannot be created by the LCID.
                throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", "culture"));
            }
            if (assembly!=typeof(Object).Module.Assembly) {
                throw new ArgumentException(Environment.GetResourceString("Argument_OnlyMscorlib"));
            }

            // culture is verified to see if it is valid when CompareInfo is constructed.

            GlobalizationAssembly ga = GlobalizationAssembly.GetGlobalizationAssembly(assembly);
            Object compInfo = ga.compareInfoCache[culture];
            if (compInfo == null) {
                lock (InternalSyncObject) {
                    //
                    // Re-check again to make sure that no one has created the CompareInfo for the culture yet before the current
                    // thread enters this sync block.
                    //
                    if ((compInfo = ga.compareInfoCache[culture]) == null) {
                        compInfo = new CompareInfo(ga, culture);
                        System.Threading.Thread.MemoryBarrier();
                        ga.compareInfoCache[culture] = compInfo;
                    }
                }
            }

            return ((CompareInfo)compInfo);
        }

Same methods

CompareInfo::GetCompareInfo ( String name ) : CompareInfo
CompareInfo::GetCompareInfo ( String name, Assembly assembly ) : CompareInfo
CompareInfo::GetCompareInfo ( int culture ) : CompareInfo

Usage Example

Beispiel #1
0
 ////////////////////////////////////////////////////////////////////////
 //
 //  GetHashCode
 //
 //  Implements Object.GetHashCode().  Returns the hash code for the
 //  SortKey.  The hash code is guaranteed to be the same for
 //  SortKey A and B where A.Equals(B) is true.
 //
 ////////////////////////////////////////////////////////////////////////
 public override int GetHashCode()
 {
     return(CompareInfo.GetCompareInfo(
                this.localeName).GetHashCodeOfString(this.m_String, this.options));
 }
All Usage Examples Of System.Globalization.CompareInfo::GetCompareInfo