(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / System.Resources / ResourceSet.cs
blob53886af80ed28cd16b07c0b0ad5b35fb1c3001e2
1 //
2 // System.Resources.ResourceSet.cs
3 //
4 // Authors:
5 // Duncan Mak (duncan@ximian.com)
6 // Dick Porter (dick@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 //
9 // (C) 2001, 2002 Ximian, Inc. http://www.ximian.com
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Collections;
36 using System.IO;
37 using System.Globalization;
38 using System.Runtime.InteropServices;
40 namespace System.Resources
42 [Serializable]
43 public class ResourceSet : IDisposable
45 #if (NET_1_1)
46 , IEnumerable
47 #endif
51 protected IResourceReader Reader;
52 protected Hashtable Table;
54 // Constructors
55 protected ResourceSet () {}
57 public ResourceSet (IResourceReader reader)
59 if (reader == null)
60 throw new ArgumentNullException ("The reader is null.");
61 Reader = reader;
64 public ResourceSet (Stream stream)
66 if(stream==null) {
67 throw new ArgumentNullException("stream is null");
70 if(!stream.CanRead) {
71 throw new ArgumentException("stream is not readable");
74 Reader = new ResourceReader (stream);
77 public ResourceSet (String fileName)
79 if(fileName==null) {
80 throw new ArgumentNullException("filename is null");
83 Reader = new ResourceReader (fileName);
86 public virtual void Close ()
88 Dispose (true);
91 public void Dispose()
93 Dispose (true);
96 protected virtual void Dispose (bool disposing)
98 if (disposing) {
99 if(Reader!=null) {
100 Reader.Close();
104 Reader = null;
105 Table = null;
108 public virtual Type GetDefaultReader ()
110 return (typeof (ResourceReader));
112 public virtual Type GetDefaultWriter ()
114 return (typeof (ResourceWriter));
117 #if (NET_1_1)
119 [ComVisible (false)]
120 public virtual IDictionaryEnumerator GetEnumerator ()
122 if (Table == null)
123 ReadResources ();
124 return Table.GetEnumerator();
127 IEnumerator IEnumerable.GetEnumerator ()
129 return this.GetEnumerator ();
132 #endif
134 public virtual object GetObject (string name)
136 if (name == null)
137 throw new ArgumentNullException ("The name parameter is null.");
138 if (Reader == null)
139 throw new InvalidOperationException ("The ResourceSet has been closed.");
141 if (Table == null) {
142 ReadResources ();
145 return(Table[name]);
148 public virtual object GetObject (string name, bool ignoreCase)
150 if (name == null)
151 throw new ArgumentNullException ("The name parameter is null.");
152 if (Reader == null)
153 throw new InvalidOperationException ("ResourceSet has been closed.");
154 if (Table == null)
155 ReadResources ();
157 if (ignoreCase) {
158 foreach (DictionaryEntry de in Table) {
159 string key = (string) de.Key;
160 if (String.Compare (key, name, true, CultureInfo.InvariantCulture) == 0)
161 return de.Value;
163 return null;
164 } else
165 return Table[name];
168 public virtual string GetString (string name)
170 Object o = GetObject (name);
171 if (o == null)
172 return null;
173 if (o is string)
174 return (string) o;
175 throw new InvalidOperationException("Not a string");
178 public virtual string GetString (string name, bool ignoreCase)
180 Object o = GetObject (name, ignoreCase);
181 if (o == null)
182 return null;
183 if (o is string)
184 return (string) o;
185 throw new InvalidOperationException("Not a string");
188 protected virtual void ReadResources ()
190 if (Reader == null)
191 throw new InvalidOperationException ("ResourceSet is closed.");
193 IDictionaryEnumerator i = Reader.GetEnumerator();
195 if (Table == null)
196 Table = new Hashtable ();
197 i.Reset ();
199 while (i.MoveNext ())
200 Table.Add (i.Key, i.Value);