2002-01-05 Ravi Pratap <ravi@ximian.com>
[mono.git] / mcs / class / corlib / System.Resources / ResourceManager.cs
1 //      
2 // System.Resources.ResourceManager.cs
3 //
4 // Author:
5 //      Duncan Mak (duncan@ximian.com)
6 //
7 // 2001 (C) Ximian, Inc. http://www.ximian.com
8 //
9
10 using System.Collections;
11 using System.Reflection;
12 using System.Globalization;
13
14 namespace System.Resources {
15            public class ResourceManager {
16                          public static readonly int HeaderVersionNumber;
17                          public static readonly int MagicNumber;
18
19                          protected string BaseNameField;
20                          protected Assembly MainAssembly;
21                          protected Hashtable Resourcesets;
22                          
23                          private bool ignoreCase;
24                          private Type resourceSetType;
25
26                          // constructors
27                          public ResourceManager () {}
28
29                          [MonoTODO]
30                          public ResourceManager (Type resourceSource) {
31                                     if (resourceSource == null)
32                                                   throw new ArgumentNullException ("resourceSource is null.");
33                                     resourceSetType = resourceSource; // TODO Incomplete
34                          }
35
36                          [MonoTODO]
37                          public ResourceManager (string baseName, Assembly assembly) {
38                                     if (baseName == null || assembly == null)
39                                                   throw new ArgumentNullException ("The arguments are null.");
40                                     // TODO
41                          }
42                          public ResourceManager (string baseName, Assembly assembly, Type usingResourceSet) {
43                                     if (baseName == null || assembly == null)
44                                                   throw new ArgumentNullException ("The arguments are null.");
45
46                                     if (usingResourceSet != null)
47                                                   if (!usingResourceSet.isSubclassOf (Typeof (ResourceSet)))
48                                                          throw new ArgumentException ("Type must be derived from ResourceSet.");
49                          }
50
51                          public static ResourceManager CreateFileBasedResourceManager (string baseName,
52                                                                                                                            string resourceDir,
53                                                                                                                            Type usingResourceSet) {}
54
55                          public virtual string BaseName { get { return BaseNameField; }}
56
57                          public virtual bool IgnoreCase {
58                                     get { return ignoreCase; }
59                                     set { ignoreCase = value; }
60                          }
61
62                          public virtual Type ResourceSetType { get { return resourceSetType; }}
63                          
64                          public virtual ResourceSet GetResourceSet (CultureInfo culture,
65                                                                                             bool createIfNotExists,
66                                                                                             bool tryParents) {
67                                     if (culture == null)
68                                                   throw new ArgumentNullException ("CultureInfo is a null reference.");
69                          }
70
71                          [MonoTODO]
72                          public virtual string GetString (string name) {
73                                     if (name == null)
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 " +
78                                                                                                      "not a string.");
79                                                   return ResourceSets[name].ToString();
80                                     }
81                                     // TODO check for correctness.                                  
82                          }
83                          
84                          public virtual string GetString (string name, CultureInfo culture) {
85                                     if (name == null)
86                                                   throw new ArgumentNullException ("Name is null.");
87                                 return name;
88                          }
89
90                          [MonoTODO]
91                          protected virtual string GetResourceFileName (CultureInfo culture) {
92                                     return new culture.Name + ".resources"; // TODO check for correctness.
93                          }
94
95                          protected virtual ResourceSet InternalGetResourceSet (CultureInfo culture,
96                                                                                bool Createifnotexists,
97                                                                                bool tryParents) {}
98                    
99                          public virtual void ReleaseAllResources () {
100                                     foreach (ResourceSet r in ResourceSets)
101                                                   r.Close();
102                          }
103
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);
108                                     }
109                                     return null;
110                          }
111
112                          public static Version GetSatelliteContractVersion (Assembly a) {
113
114                                     foreach (Attribute attribute in a.GetCustomAttributes ()) {
115                                                   if (attribute is SatelliteContractVersionAttribute)
116                                                                 return new Version (attribute.Version);
117                                     }
118                                     return null;
119                          }
120            }
121 }