System.Globalization.GlobalizationAssembly.GetGlobalizationAssembly C# (CSharp) Méthode

GetGlobalizationAssembly() static private méthode

static private GetGlobalizationAssembly ( Assembly assembly ) : GlobalizationAssembly
assembly System.Reflection.Assembly
Résultat GlobalizationAssembly
        internal static GlobalizationAssembly GetGlobalizationAssembly(Assembly assembly) {
            GlobalizationAssembly ga;

            if ((ga = (GlobalizationAssembly)m_assemblyHash[assembly]) == null) 
            {
                // This is intentionally taking a process-global lock on an
                // internal Type, using ExecuteCodeWithLock to guarantee we 
                // release the lock in a stack overflow safe way.
                RuntimeHelpers.TryCode createGlobalizationAssem = new RuntimeHelpers.TryCode(CreateGlobalizationAssembly);
                RuntimeHelpers.ExecuteCodeWithLock(typeof(CultureTableRecord),
                                                    createGlobalizationAssem,
                                                    assembly);
                ga = (GlobalizationAssembly)m_assemblyHash[assembly];
            }            
            BCLDebug.Assert(ga != null, "GlobalizationAssembly was not created");
            return (ga);
        }

Usage Example

Exemple #1
0
        /*=================================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);
        }
All Usage Examples Of System.Globalization.GlobalizationAssembly::GetGlobalizationAssembly