internal Version ObtainSatelliteContractVersion(Assembly a)
 {
     return(ResourceManager.GetSatelliteContractVersion(a));
 }
예제 #2
0
        /// <summary>Provides the implementation for finding a <see cref="T:System.Resources.ResourceSet" />.</summary>
        /// <returns>The specified <see cref="T:System.Resources.ResourceSet" />.</returns>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to look for. </param>
        /// <param name="createIfNotExists">If true and if the <see cref="T:System.Resources.ResourceSet" /> has not been loaded yet, load it. </param>
        /// <param name="tryParents">If the <see cref="T:System.Resources.ResourceSet" /> cannot be loaded, try parent <see cref="T:System.Globalization.CultureInfo" /> objects to see if they exist. </param>
        /// <exception cref="T:System.Resources.MissingManifestResourceException">The main assembly does not contain a .resources file and it is required to look up a resource. </exception>
        /// <exception cref="T:System.ExecutionEngineException">There was an internal error in the runtime.</exception>
        /// <exception cref="T:System.Resources.MissingSatelliteAssemblyException">The satellite assembly associated with <paramref name="culture" /> could not be located.</exception>
        protected virtual ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("key");
            }
            ResourceSet resourceSet = (ResourceSet)this.ResourceSets[culture];

            if (resourceSet != null)
            {
                return(resourceSet);
            }
            if (ResourceManager.NonExistent.Contains(culture))
            {
                return(null);
            }
            if (this.MainAssembly != null)
            {
                CultureInfo cultureInfo = culture;
                if (culture.Equals(this.neutral_culture))
                {
                    cultureInfo = CultureInfo.InvariantCulture;
                }
                Stream stream           = null;
                string resourceFileName = this.GetResourceFileName(cultureInfo);
                if (!cultureInfo.Equals(CultureInfo.InvariantCulture))
                {
                    Version satelliteContractVersion = ResourceManager.GetSatelliteContractVersion(this.MainAssembly);
                    try
                    {
                        Assembly satelliteAssemblyNoThrow = this.MainAssembly.GetSatelliteAssemblyNoThrow(cultureInfo, satelliteContractVersion);
                        if (satelliteAssemblyNoThrow != null)
                        {
                            stream = satelliteAssemblyNoThrow.GetManifestResourceStream(resourceFileName);
                            if (stream == null)
                            {
                                stream = this.GetManifestResourceStreamNoCase(satelliteAssemblyNoThrow, resourceFileName);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    stream = this.MainAssembly.GetManifestResourceStream(this.resourceSource, resourceFileName);
                    if (stream == null)
                    {
                        stream = this.GetManifestResourceStreamNoCase(this.MainAssembly, resourceFileName);
                    }
                }
                if (stream != null && createIfNotExists)
                {
                    object[] args = new object[]
                    {
                        stream
                    };
                    resourceSet = (ResourceSet)Activator.CreateInstance(this.resourceSetType, args);
                }
                else if (cultureInfo.Equals(CultureInfo.InvariantCulture))
                {
                    throw this.AssemblyResourceMissing(resourceFileName);
                }
            }
            else if (this.resourceDir != null || this.BaseNameField != null)
            {
                string resourceFilePath = this.GetResourceFilePath(culture);
                if (createIfNotExists && File.Exists(resourceFilePath))
                {
                    object[] args2 = new object[]
                    {
                        resourceFilePath
                    };
                    resourceSet = (ResourceSet)Activator.CreateInstance(this.resourceSetType, args2);
                }
                else if (culture.Equals(CultureInfo.InvariantCulture))
                {
                    string message = string.Format("Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.{0}baseName: {1}  locationInfo: {2}  fileName: {3}", new object[]
                    {
                        Environment.NewLine,
                        this.BaseNameField,
                        "<null>",
                        this.GetResourceFileName(culture)
                    });
                    throw new MissingManifestResourceException(message);
                }
            }
            if (resourceSet == null && tryParents && !culture.Equals(CultureInfo.InvariantCulture))
            {
                resourceSet = this.InternalGetResourceSet(culture.Parent, createIfNotExists, tryParents);
            }
            if (resourceSet != null)
            {
                this.ResourceSets[culture] = resourceSet;
            }
            else
            {
                ResourceManager.NonExistent[culture] = culture;
            }
            return(resourceSet);
        }