using System; using System.Collections; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.InteropServices; namespace System.Resources { /// Provides convenient access to culture-specific resources at run time. // Token: 0x02000277 RID: 631 [ComVisible(true)] [Serializable] public class ResourceManager { /// Initializes a new instance of the class with default values. // Token: 0x06002038 RID: 8248 RVA: 0x00074E3C File Offset: 0x0007303C protected ResourceManager() { } /// Creates a that looks up resources in satellite assemblies based on information from the specified . /// A from which the derives all information for finding .resources files. /// The parameter is null. // Token: 0x06002039 RID: 8249 RVA: 0x00074E54 File Offset: 0x00073054 public ResourceManager(Type resourceSource) { if (resourceSource == null) { throw new ArgumentNullException("resourceSource"); } this.resourceSource = resourceSource; this.BaseNameField = resourceSource.Name; this.MainAssembly = resourceSource.Assembly; this.ResourceSets = ResourceManager.GetResourceSets(this.MainAssembly, this.BaseNameField); this.neutral_culture = ResourceManager.GetNeutralResourcesLanguage(this.MainAssembly); } /// Initializes a new instance of the class that looks up resources contained in files with the specified root name using the given assembly. /// The root name of the resource file without its extension and along with any fully qualified namespace name. For example, the root name for the resource file named "MyApplication.MyResource.en-US.resources" is "MyApplication.MyResource". /// The main assembly for the resources. /// The or parameter is null. // Token: 0x0600203A RID: 8250 RVA: 0x00074ED0 File Offset: 0x000730D0 public ResourceManager(string baseName, Assembly assembly) { if (baseName == null) { throw new ArgumentNullException("baseName"); } if (assembly == null) { throw new ArgumentNullException("assembly"); } this.BaseNameField = baseName; this.MainAssembly = assembly; this.ResourceSets = ResourceManager.GetResourceSets(this.MainAssembly, this.BaseNameField); this.neutral_culture = ResourceManager.GetNeutralResourcesLanguage(this.MainAssembly); } /// Initializes a new instance of the class that looks up resources contained in files derived from the specified root name using the given . /// The root name of the resource file without its extension and along with any fully qualified namespace name. For example, the root name for the resource file named "MyApplication.MyResource.en-US.resources" is "MyApplication.MyResource". /// The main assembly for the resources. /// The of the custom to use. If null, the default runtime is used. /// /// is not a derived class of . /// The or parameter is null. // Token: 0x0600203B RID: 8251 RVA: 0x00074F4C File Offset: 0x0007314C public ResourceManager(string baseName, Assembly assembly, Type usingResourceSet) { if (baseName == null) { throw new ArgumentNullException("baseName"); } if (assembly == null) { throw new ArgumentNullException("assembly"); } this.BaseNameField = baseName; this.MainAssembly = assembly; this.ResourceSets = ResourceManager.GetResourceSets(this.MainAssembly, this.BaseNameField); this.resourceSetType = this.CheckResourceSetType(usingResourceSet, true); this.neutral_culture = ResourceManager.GetNeutralResourcesLanguage(this.MainAssembly); } // Token: 0x0600203C RID: 8252 RVA: 0x00074FD8 File Offset: 0x000731D8 private ResourceManager(string baseName, string resourceDir, Type usingResourceSet) { if (baseName == null) { throw new ArgumentNullException("baseName"); } if (resourceDir == null) { throw new ArgumentNullException("resourceDir"); } this.BaseNameField = baseName; this.resourceDir = resourceDir; this.resourceSetType = this.CheckResourceSetType(usingResourceSet, false); this.ResourceSets = ResourceManager.GetResourceSets(this.MainAssembly, this.BaseNameField); } // Token: 0x0600203E RID: 8254 RVA: 0x0007507C File Offset: 0x0007327C private static Hashtable GetResourceSets(Assembly assembly, string basename) { Hashtable resourceCache = ResourceManager.ResourceCache; Hashtable hashtable2; lock (resourceCache) { string text = string.Empty; if (assembly != null) { text = assembly.FullName; } else { text = basename.GetHashCode().ToString() + "@@"; } if (basename != null && basename != string.Empty) { text = text + "!" + basename; } else { text = text + "!" + text.GetHashCode(); } Hashtable hashtable = ResourceManager.ResourceCache[text] as Hashtable; if (hashtable == null) { hashtable = Hashtable.Synchronized(new Hashtable()); ResourceManager.ResourceCache[text] = hashtable; } hashtable2 = hashtable; } return hashtable2; } // Token: 0x0600203F RID: 8255 RVA: 0x00075168 File Offset: 0x00073368 private Type CheckResourceSetType(Type usingResourceSet, bool verifyType) { if (usingResourceSet == null) { return this.resourceSetType; } if (verifyType && !typeof(ResourceSet).IsAssignableFrom(usingResourceSet)) { throw new ArgumentException("Type parameter must refer to a subclass of ResourceSet.", "usingResourceSet"); } return usingResourceSet; } /// Returns a that searches a specific directory for resources instead of in the assembly manifest. /// The newly created that searches a specific directory for resources instead of in the assembly manifest. /// The root name of the resources. For example, the root name for the resource file named "MyResource.en-US.resources" is "MyResource". /// The name of the directory to search for the resources. /// The of the custom to use. If null, the default runtime is used. /// The or parameter is null. /// /// /// // Token: 0x06002040 RID: 8256 RVA: 0x000751A4 File Offset: 0x000733A4 public static ResourceManager CreateFileBasedResourceManager(string baseName, string resourceDir, Type usingResourceSet) { return new ResourceManager(baseName, resourceDir, usingResourceSet); } /// Gets the root name of the resource files that the searches for resources. /// The root name of the resource files that the searches for resources. // Token: 0x17000607 RID: 1543 // (get) Token: 0x06002041 RID: 8257 RVA: 0x000751B0 File Offset: 0x000733B0 public virtual string BaseName { get { return this.BaseNameField; } } /// Gets or sets a Boolean value indicating whether the current instance of ResourceManager allows case-insensitive resource lookups in the and methods. /// A Boolean value indicating whether the case of the resource names should be ignored. // Token: 0x17000608 RID: 1544 // (get) Token: 0x06002042 RID: 8258 RVA: 0x000751B8 File Offset: 0x000733B8 // (set) Token: 0x06002043 RID: 8259 RVA: 0x000751C0 File Offset: 0x000733C0 public virtual bool IgnoreCase { get { return this.ignoreCase; } set { this.ignoreCase = value; } } /// Gets the of the the uses to construct a object. /// The of the the uses to construct a object. // Token: 0x17000609 RID: 1545 // (get) Token: 0x06002044 RID: 8260 RVA: 0x000751CC File Offset: 0x000733CC public virtual Type ResourceSetType { get { return this.resourceSetType; } } /// Returns the value of the specified resource. /// The value of the resource localized for the caller's current culture settings. If a match is not possible, null is returned. The resource value can be null. /// The name of the resource to get. /// The parameter is null. /// No usable set of resources has been found, and there are no neutral culture resources. // Token: 0x06002045 RID: 8261 RVA: 0x000751D4 File Offset: 0x000733D4 public virtual object GetObject(string name) { return this.GetObject(name, null); } /// Gets the value of the resource localized for the specified culture. /// The value of the resource, localized for the specified culture. If a "best match" is not possible, null is returned. /// The name of the resource to get. /// The object that represents the culture for which the resource is localized. Note that if the resource is not localized for this culture, the lookup will fall back using the culture's property, stopping after checking in the neutral culture.If this value is null, the is obtained using the culture's property. /// The parameter is null. /// No usable set of resources have been found, and there are no neutral culture resources. // Token: 0x06002046 RID: 8262 RVA: 0x000751E0 File Offset: 0x000733E0 public virtual object GetObject(string name, CultureInfo culture) { if (name == null) { throw new ArgumentNullException("name"); } if (culture == null) { culture = CultureInfo.CurrentUICulture; } lock (this) { ResourceSet resourceSet = this.InternalGetResourceSet(culture, true, true); object obj; if (resourceSet != null) { obj = resourceSet.GetObject(name, this.ignoreCase); if (obj != null) { return obj; } } for (;;) { culture = culture.Parent; resourceSet = this.InternalGetResourceSet(culture, true, true); if (resourceSet != null) { obj = resourceSet.GetObject(name, this.ignoreCase); if (obj != null) { break; } } if (culture.Equals(this.neutral_culture) || culture.Equals(CultureInfo.InvariantCulture)) { goto IL_A7; } } return obj; IL_A7:; } return null; } /// Gets the for a particular culture. /// The specified . /// The to look for. /// If true and if the has not been loaded yet, load it. /// If the cannot be loaded, try parent objects to see if they exist. /// The parameter is null. // Token: 0x06002047 RID: 8263 RVA: 0x000752C0 File Offset: 0x000734C0 public virtual ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) { if (culture == null) { throw new ArgumentNullException("culture"); } ResourceSet resourceSet; lock (this) { resourceSet = this.InternalGetResourceSet(culture, createIfNotExists, tryParents); } return resourceSet; } /// Returns the value of the specified resource. /// The value of the resource localized for the caller's current culture settings. If a match is not possible, null is returned. /// The name of the resource to get. /// The parameter is null. /// The value of the specified resource is not a string. /// No usable set of resources has been found, and there are no neutral culture resources. // Token: 0x06002048 RID: 8264 RVA: 0x00075320 File Offset: 0x00073520 public virtual string GetString(string name) { return this.GetString(name, null); } /// Gets the value of the resource localized for the specified culture. /// The value of the resource localized for the specified culture. If a best match is not possible, null is returned. /// The name of the resource to get. /// The object that represents the culture for which the resource is localized. Note that if the resource is not localized for this culture, the lookup will fall back using the current thread's property, stopping after looking in the neutral culture.If this value is null, the is obtained using the current thread's property. /// The parameter is null. /// The value of the specified resource is not a . /// No usable set of resources has been found, and there are no neutral culture resources. // Token: 0x06002049 RID: 8265 RVA: 0x0007532C File Offset: 0x0007352C public virtual string GetString(string name, CultureInfo culture) { if (name == null) { throw new ArgumentNullException("name"); } if (culture == null) { culture = CultureInfo.CurrentUICulture; } lock (this) { ResourceSet resourceSet = this.InternalGetResourceSet(culture, true, true); string text; if (resourceSet != null) { text = resourceSet.GetString(name, this.ignoreCase); if (text != null) { return text; } } for (;;) { culture = culture.Parent; resourceSet = this.InternalGetResourceSet(culture, true, true); if (resourceSet != null) { text = resourceSet.GetString(name, this.ignoreCase); if (text != null) { break; } } if (culture.Equals(this.neutral_culture) || culture.Equals(CultureInfo.InvariantCulture)) { goto IL_A7; } } return text; IL_A7:; } return null; } /// Generates the name for the resource file for the given . /// The name that can be used for a resource file for the given . /// The for which a resource file name is constructed. // Token: 0x0600204A RID: 8266 RVA: 0x0007540C File Offset: 0x0007360C protected virtual string GetResourceFileName(CultureInfo culture) { if (culture.Equals(CultureInfo.InvariantCulture)) { return this.BaseNameField + ".resources"; } return this.BaseNameField + "." + culture.Name + ".resources"; } // Token: 0x0600204B RID: 8267 RVA: 0x00075458 File Offset: 0x00073658 private string GetResourceFilePath(CultureInfo culture) { if (this.resourceDir != null) { return Path.Combine(this.resourceDir, this.GetResourceFileName(culture)); } return this.GetResourceFileName(culture); } // Token: 0x0600204C RID: 8268 RVA: 0x00075480 File Offset: 0x00073680 private Stream GetManifestResourceStreamNoCase(Assembly ass, string fn) { string manifestResourceName = this.GetManifestResourceName(fn); foreach (string text in ass.GetManifestResourceNames()) { if (string.Compare(manifestResourceName, text, true, CultureInfo.InvariantCulture) == 0) { return ass.GetManifestResourceStream(text); } } return null; } /// Returns an object from the specified resource. /// An object. /// The name of a resource. /// The value of the specified resource is not a object. /// /// is null. /// No usable set of resources is found, and there are no neutral resources. // Token: 0x0600204D RID: 8269 RVA: 0x000754D0 File Offset: 0x000736D0 [CLSCompliant(false)] [ComVisible(false)] public UnmanagedMemoryStream GetStream(string name) { return this.GetStream(name, null); } /// Returns an object from the specified resource, using the specified culture. /// An object. /// The name of a resource. /// A object that specifies the culture to use for the resource lookup. If is null, the culture for the current thread is used. /// The value of the specified resource is not a object. /// /// is null. /// No usable set of resources is found, and there are no neutral resources. // Token: 0x0600204E RID: 8270 RVA: 0x000754DC File Offset: 0x000736DC [CLSCompliant(false)] [ComVisible(false)] public UnmanagedMemoryStream GetStream(string name, CultureInfo culture) { if (name == null) { throw new ArgumentNullException("name"); } if (culture == null) { culture = CultureInfo.CurrentUICulture; } ResourceSet resourceSet = this.InternalGetResourceSet(culture, true, true); return resourceSet.GetStream(name, this.ignoreCase); } /// Provides the implementation for finding a . /// The specified . /// The to look for. /// If true and if the has not been loaded yet, load it. /// If the cannot be loaded, try parent objects to see if they exist. /// The main assembly does not contain a .resources file and it is required to look up a resource. /// There was an internal error in the runtime. /// The satellite assembly associated with could not be located. // Token: 0x0600204F RID: 8271 RVA: 0x00075520 File Offset: 0x00073720 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[] array = new object[] { stream }; resourceSet = (ResourceSet)Activator.CreateInstance(this.resourceSetType, array); } 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[] array2 = new object[] { resourceFilePath }; resourceSet = (ResourceSet)Activator.CreateInstance(this.resourceSetType, array2); } else if (culture.Equals(CultureInfo.InvariantCulture)) { string text = 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, "", this.GetResourceFileName(culture) }); throw new MissingManifestResourceException(text); } } 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; } /// Tells the to call on all objects and release all resources. // Token: 0x06002050 RID: 8272 RVA: 0x00075778 File Offset: 0x00073978 public virtual void ReleaseAllResources() { lock (this) { foreach (object obj in this.ResourceSets.Values) { ResourceSet resourceSet = (ResourceSet)obj; resourceSet.Close(); } this.ResourceSets.Clear(); } } /// Returns the for the main assembly's neutral resources by reading the value of the on a specified . /// The culture from the , if found; otherwise, . /// The assembly for which to return a . // Token: 0x06002051 RID: 8273 RVA: 0x00075824 File Offset: 0x00073A24 protected static CultureInfo GetNeutralResourcesLanguage(Assembly a) { object[] customAttributes = a.GetCustomAttributes(typeof(NeutralResourcesLanguageAttribute), false); if (customAttributes.Length == 0) { return CultureInfo.InvariantCulture; } NeutralResourcesLanguageAttribute neutralResourcesLanguageAttribute = (NeutralResourcesLanguageAttribute)customAttributes[0]; return new CultureInfo(neutralResourcesLanguageAttribute.CultureName); } /// Returns the specified by the in the given assembly. /// The satellite contract of the given assembly, or null if no version was found. /// The for which to look up the . /// The found in the assembly is invalid. // Token: 0x06002052 RID: 8274 RVA: 0x00075868 File Offset: 0x00073A68 protected static Version GetSatelliteContractVersion(Assembly a) { object[] customAttributes = a.GetCustomAttributes(typeof(SatelliteContractVersionAttribute), false); if (customAttributes.Length == 0) { return null; } SatelliteContractVersionAttribute satelliteContractVersionAttribute = (SatelliteContractVersionAttribute)customAttributes[0]; return new Version(satelliteContractVersionAttribute.Version); } /// Gets or sets the location from which to retrieve neutral fallback resources. /// One of the values. // Token: 0x1700060A RID: 1546 // (get) Token: 0x06002053 RID: 8275 RVA: 0x000758A8 File Offset: 0x00073AA8 // (set) Token: 0x06002054 RID: 8276 RVA: 0x000758B0 File Offset: 0x00073AB0 [MonoTODO("the property exists but is not respected")] protected UltimateResourceFallbackLocation FallbackLocation { get { return this.fallbackLocation; } set { this.fallbackLocation = value; } } // Token: 0x06002055 RID: 8277 RVA: 0x000758BC File Offset: 0x00073ABC private MissingManifestResourceException AssemblyResourceMissing(string fileName) { AssemblyName assemblyName = ((this.MainAssembly == null) ? null : this.MainAssembly.GetName()); string manifestResourceName = this.GetManifestResourceName(fileName); string text = string.Format("Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"{0}\" was correctly embedded or linked into assembly \"{1}\" at compile time, or that all the satellite assemblies required are loadable and fully signed.", manifestResourceName, (assemblyName == null) ? string.Empty : assemblyName.Name); throw new MissingManifestResourceException(text); } // Token: 0x06002056 RID: 8278 RVA: 0x00075918 File Offset: 0x00073B18 private string GetManifestResourceName(string fn) { string text; if (this.resourceSource != null) { if (this.resourceSource.Namespace != null && this.resourceSource.Namespace.Length > 0) { text = this.resourceSource.Namespace + "." + fn; } else { text = fn; } } else { text = fn; } return text; } // Token: 0x04000B48 RID: 2888 private static Hashtable ResourceCache = new Hashtable(); // Token: 0x04000B49 RID: 2889 private static Hashtable NonExistent = Hashtable.Synchronized(new Hashtable()); /// A constant readonly value indicating the version of resource file headers that the current implementation of can interpret and produce. // Token: 0x04000B4A RID: 2890 public static readonly int HeaderVersionNumber = 1; /// Holds the number used to identify resource files. // Token: 0x04000B4B RID: 2891 public static readonly int MagicNumber = -1091581234; /// Indicates the root name of the resource files that the searches for resources. // Token: 0x04000B4C RID: 2892 protected string BaseNameField; /// Indicates the main that contains the resources. // Token: 0x04000B4D RID: 2893 protected Assembly MainAssembly; /// Contains a that returns a mapping from cultures to objects. // Token: 0x04000B4E RID: 2894 protected Hashtable ResourceSets; // Token: 0x04000B4F RID: 2895 private bool ignoreCase; // Token: 0x04000B50 RID: 2896 private Type resourceSource; // Token: 0x04000B51 RID: 2897 private Type resourceSetType = typeof(RuntimeResourceSet); // Token: 0x04000B52 RID: 2898 private string resourceDir; // Token: 0x04000B53 RID: 2899 private CultureInfo neutral_culture; // Token: 0x04000B54 RID: 2900 private UltimateResourceFallbackLocation fallbackLocation; } }