2 // System.Resources.ResourceManager.cs
5 // Duncan Mak (duncan@ximian.com)
7 // 2001 (C) Ximian, Inc. http://www.ximian.com
10 using System.Collections;
11 using System.Reflection;
12 using System.Globalization;
14 namespace System.Resources {
15 public class ResourceManager {
16 public static readonly int HeaderVersionNumber;
17 public static readonly int MagicNumber;
19 protected string BaseNameField;
20 protected Assembly MainAssembly;
21 protected Hashtable Resourcesets;
23 private bool ignoreCase;
24 private Type resourceSetType;
27 public ResourceManager () {}
30 public ResourceManager (Type resourceSource) {
31 if (resourceSource == null)
32 throw new ArgumentNullException ("resourceSource is null.");
33 resourceSetType = resourceSource; // TODO Incomplete
37 public ResourceManager (string baseName, Assembly assembly) {
38 if (baseName == null || assembly == null)
39 throw new ArgumentNullException ("The arguments are null.");
42 public ResourceManager (string baseName, Assembly assembly, Type usingResourceSet) {
43 if (baseName == null || assembly == null)
44 throw new ArgumentNullException ("The arguments are null.");
46 if (usingResourceSet != null)
47 if (!usingResourceSet.isSubclassOf (Typeof (ResourceSet)))
48 throw new ArgumentException ("Type must be derived from ResourceSet.");
51 public static ResourceManager CreateFileBasedResourceManager (string baseName,
53 Type usingResourceSet) {}
55 public virtual string BaseName { get { return BaseNameField; }}
57 public virtual bool IgnoreCase {
58 get { return ignoreCase; }
59 set { ignoreCase = value; }
62 public virtual Type ResourceSetType { get { return resourceSetType; }}
64 public virtual ResourceSet GetResourceSet (CultureInfo culture,
65 bool createIfNotExists,
68 throw new ArgumentNullException ("CultureInfo is a null reference.");
72 public virtual string GetString (string name) {
74 throw new ArgumentNullException ("Name is null.");
75 if (ResourceSets.Contains (name)) {
76 if (!ResourceSets[name] is string)
77 throw new InvalidOperationException ("The resource is " +
79 return ResourceSets[name].ToString();
81 // TODO check for correctness.
84 public virtual string GetString (string name, CultureInfo culture) {
86 throw new ArgumentNullException ("Name is null.");
91 protected virtual string GetResourceFileName (CultureInfo culture) {
92 return new culture.Name + ".resources"; // TODO check for correctness.
95 protected virtual ResourceSet InternalGetResourceSet (CultureInfo culture,
96 bool Createifnotexists,
99 public virtual void ReleaseAllResources () {
100 foreach (ResourceSet r in ResourceSets)
104 protected static CultureInfo GetNeutralResourcesLanguage (Assembly a) {
105 foreach (Attribute attribute in a.GetCustomAttributes ()) {
106 if (attribute is NeutralResourcesLanguageAttribute)
107 return new Cultureinfo (attribute.CultureName);
112 public static Version GetSatelliteContractVersion (Assembly a) {
114 foreach (Attribute attribute in a.GetCustomAttributes ()) {
115 if (attribute is SatelliteContractVersionAttribute)
116 return new Version (attribute.Version);