示例#1
0
        /// <summary>
        /// Instantiates a resource set for a given culture.
        /// </summary>
        /// <exception cref="ArgumentException">
        ///   The expected type name is not valid.
        /// </exception>
        /// <exception cref="ReflectionTypeLoadException">
        ///   satelliteAssembly does not contain the expected type.
        /// </exception>
        /// <exception cref="NullReferenceException">
        ///   The type has no no-arguments constructor.
        /// </exception>
        private static GettextResourceSet InstantiateResourceSet(Assembly satelliteAssembly, String resourceName, CultureInfo culture)
        {
            // We expect a class with a culture dependent class name.
            Type clazz = satelliteAssembly.GetType(GettextResourceManager.ConstructClassName(resourceName) + "_" + culture.Name.Replace('-', '_'));
            // We expect it has a no-argument constructor, and invoke it.
            ConstructorInfo constructor = clazz.GetConstructor(Type.EmptyTypes);

            return((GettextResourceSet)constructor.Invoke(null));
        }
示例#2
0
 /// <summary>
 /// Loads and returns the satellite assembly for a given culture.
 /// </summary>
 private Assembly MySatelliteAssembly(CultureInfo culture)
 {
     return(GettextResourceManager.GetSatelliteAssembly(MainAssembly, this.BaseName, culture));
 }
示例#3
0
 /// <summary>
 /// Returns the array of <c>GettextResourceSet</c>s for a given culture,
 /// loading them if necessary, and maintaining the cache.
 /// </summary>
 private GettextResourceSet[] GetResourceSetsFor(CultureInfo culture)
 {
     //Console.WriteLine(">> GetResourceSetsFor "+culture);
     // Look up in the cache.
     GettextResourceSet[] result = (GettextResourceSet[])_loaded[culture];
     if (result == null)
     {
         lock (this)
         {
             // Look up again - maybe another thread has filled in the entry
             // while we slept waiting for the lock.
             result = (GettextResourceSet[])_loaded[culture];
             if (result == null)
             {
                 // Determine the GettextResourceSets for the given culture.
                 if (culture.Parent == null || culture.Equals(CultureInfo.InvariantCulture))
                 {
                     // Invariant culture.
                     result = EmptyResourceSetArray;
                 }
                 else
                 {
                     // Use a satellite assembly as primary GettextResourceSet, and
                     // the result for the parent culture as fallback.
                     GettextResourceSet[] parentResult = this.GetResourceSetsFor(culture.Parent);
                     Assembly             satelliteAssembly;
                     try
                     {
                         satelliteAssembly = this.MySatelliteAssembly(culture);
                     }
                     catch (FileNotFoundException)
                     {
                         satelliteAssembly = null;
                     }
                     if (satelliteAssembly != null)
                     {
                         GettextResourceSet satelliteResourceSet;
                         try
                         {
                             satelliteResourceSet = GettextResourceManager.InstantiateResourceSet(satelliteAssembly, this.BaseName, culture);
                         }
                         catch (Exception e)
                         {
                             Console.Error.WriteLine(e);
                             Console.Error.WriteLine(e.StackTrace);
                             satelliteResourceSet = null;
                         }
                         if (satelliteResourceSet != null)
                         {
                             result    = new GettextResourceSet[1 + parentResult.Length];
                             result[0] = satelliteResourceSet;
                             Array.Copy(parentResult, 0, result, 1, parentResult.Length);
                         }
                         else
                         {
                             result = parentResult;
                         }
                     }
                     else
                     {
                         result = parentResult;
                     }
                 }
                 // Put the result into the cache.
                 _loaded.Add(culture, result);
             }
         }
     }
     //Console.WriteLine("<< GetResourceSetsFor "+culture);
     return(result);
 }