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