/*=================================GetCompareInfo========================== **Action: Get the CompareInfo constructed from the data table in the specified assembly for the specified culture. ** The purpose of this method is to provide versioning for CompareInfo tables. ** If you pass Assembly which contains different sorting table, you will sort your strings using the data ** in the assembly. **Returns: The CompareInfo for the specified culture. **Arguments: ** culture the ID of the culture ** assembly the assembly which contains the sorting table. **Exceptions: ** ArugmentNullException when the assembly is null ** ArgumentException if culture is invalid. **============================================================================*/ /* Note: The design goal here is that we can still provide version even when the underlying algorithm for CompareInfo * is totally changed in the future. * In the case that the algorithm for CompareInfo is changed, we can use this method to * provide the old algorithm for the old tables. The idea is to change the implementation for GetCompareInfo() * to something like: * 1. Check the ID of the assembly. * 2. If the assembly needs old code, create an instance of the old CompareInfo class. The name of CompareInfo * will be like CompareInfoVersion1 and extends from CompareInfo. * 3. Otherwise, create an instance of the current CompareInfo. * The CompareInfo ctor always provides the implementation for the current data table. */ /// <include file='doc\CompareInfo.uex' path='docs/doc[@for="CompareInfo.GetCompareInfo"]/*' /> public static CompareInfo GetCompareInfo(int culture, Assembly assembly) { // Parameter checking. if (assembly == null) { throw new ArgumentNullException("assembly"); } 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 (typeof(GlobalizationAssembly)) { // // 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); ga.compareInfoCache[culture] = compInfo; } } } return((CompareInfo)compInfo); }
private static CompareInfo GetCompareInfoWithPrefixedLcid(int cultureKey, Assembly assembly, int prefix) { if (assembly == null) { throw new ArgumentNullException("assembly"); } int cultureId = cultureKey & ~prefix; if (System.Globalization.CultureTableRecord.IsCustomCultureId(cultureId)) { throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", new object[] { "culture" })); } if (assembly != typeof(object).Module.Assembly) { throw new ArgumentException(Environment.GetResourceString("Argument_OnlyMscorlib")); } GlobalizationAssembly globalizationAssembly = GlobalizationAssembly.GetGlobalizationAssembly(assembly); object obj2 = globalizationAssembly.compareInfoCache[cultureKey]; if (obj2 == null) { lock (InternalSyncObject) { obj2 = globalizationAssembly.compareInfoCache[cultureKey]; if (obj2 == null) { obj2 = new CompareInfo(globalizationAssembly, cultureId); Thread.MemoryBarrier(); globalizationAssembly.compareInfoCache[cultureKey] = obj2; } } } return((CompareInfo)obj2); }