Huge indentation fix. Don't worry, I tested so no typos were introduced. ;-)
[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 {
16         [Serializable]
17         public class ResourceManager
18         {
19                 public static readonly int HeaderVersionNumber;
20                 // public static readonly int MagicNumber = 0xBEEFCACE;
21
22                 protected string BaseNameField;
23                 protected Assembly MainAssembly;
24                 protected Hashtable ResourceSets;
25                 
26                 private bool ignoreCase;
27                 private Type resourceSetType;
28                 
29                 // constructors
30                 public ResourceManager () {}
31                 
32                 public ResourceManager (Type resourceSource)
33                 {
34                         if (resourceSource == null)
35                                 throw new ArgumentNullException ("resourceSource is null.");
36                         
37                         BaseNameField = resourceSource.FullName;
38                         MainAssembly = resourceSource.Assembly;
39                         
40                         ignoreCase = false;
41                         resourceSetType = resourceSource;
42                 }
43                 
44                 public ResourceManager (string baseName, Assembly assembly)
45                 {
46                         if (baseName == null || assembly == null)
47                                 throw new ArgumentNullException ("The arguments are null.");
48                         
49                         BaseNameField = baseName;
50                         MainAssembly = assembly;
51                         ignoreCase = false;
52                         resourceSetType = typeof (ResourceSet);
53                 }
54                          
55                 public ResourceManager (string baseName, Assembly assembly, Type usingResourceSet)
56                 {
57                         if (baseName == null || assembly == null)
58                                 throw new ArgumentNullException ("The arguments are null.");
59                         
60                         BaseNameField = baseName;
61                         MainAssembly = assembly;
62                         
63                         if (usingResourceSet == null) // defaults resourceSet type.
64                                 resourceSetType = typeof (ResourceSet);
65                         else {
66                                 if (!usingResourceSet.IsSubclassOf (typeof (ResourceSet)))
67                                         throw new ArgumentException ("Type must be from ResourceSet.");
68                                 
69                         }
70                 }
71                 
72                 [MonoTODO]
73                 public static ResourceManager CreateFileBasedResourceManager (string baseName,
74                                                       string resourceDir, Type usingResourceSet)
75                 {
76                         return null;
77                 }
78
79                 public virtual string BaseName
80                 {
81                         get { return BaseNameField; }
82                 }
83
84                 public virtual bool IgnoreCase
85                 {
86                         get { return ignoreCase; }
87                         set { ignoreCase = value; }
88                 }
89
90                 public virtual Type ResourceSetType
91                 {
92                         get { return resourceSetType; }
93                 }
94                          
95                 [MonoTODO]
96                 public virtual ResourceSet GetResourceSet (CultureInfo culture,
97                                            bool createIfNotExists, bool tryParents)
98                         
99                 {
100                         if (culture == null)
101                                 throw new ArgumentNullException ("CultureInfo is a null reference.");
102                         return null;
103                 }
104                 
105                 [MonoTODO]
106                 public virtual string GetString (string name)
107                 {
108                         if (name == null)
109                                 throw new ArgumentNullException ("Name is null.");
110                         if (ResourceSets.Contains (name)) {
111                                 if (!(ResourceSets[name] is string))
112                                         throw new InvalidOperationException ("The resource is " +
113                                                                              "not a string.");
114                                 return ResourceSets[name].ToString();
115                         }
116                         return null;    
117                 }
118
119                 [MonoTODO]
120                 public virtual string GetString (string name, CultureInfo culture)
121                 {
122                                  if (name == null)
123                                          throw new ArgumentNullException ("Name is null.");
124                                  return null;
125                 }
126
127                 protected virtual string GetResourceFileName (CultureInfo culture)
128                 {
129                         return culture.Name + ".resources";
130                 }
131
132                 [MonoTODO]
133                 protected virtual ResourceSet InternalGetResourceSet (CultureInfo culture,
134                                                    bool Createifnotexists, bool tryParents)
135                          {
136                                  return null;
137                          }
138                    
139                 public virtual void ReleaseAllResources ()
140                 {
141                         foreach (ResourceSet r in ResourceSets)
142                                 r.Close();
143                 }
144
145                 protected static CultureInfo GetNeutralResourcesLanguage (Assembly a)
146                 {
147                         foreach (Attribute attribute in a.GetCustomAttributes (false)) {
148                                 if (attribute is NeutralResourcesLanguageAttribute)
149                                         return new CultureInfo ((attribute as NeutralResourcesLanguageAttribute).CultureName);
150                         }
151                         return null;
152                 }
153
154                 protected static Version GetSatelliteContractVersion (Assembly a)
155                 {
156                         foreach (Attribute attribute in a.GetCustomAttributes (false)) {
157                                 if (attribute is SatelliteContractVersionAttribute)
158                                         return new Version ((attribute as SatelliteContractVersionAttribute).Version);
159                         }
160                         return null; // return null if no version was found.
161                 }
162         }
163 }