2 // System.Resources.ResourceSet.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Dick Porter (dick@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (C) 2001, 2002 Ximian, Inc. http://www.ximian.com
12 using System.Collections;
14 using System.Globalization;
15 using System.Runtime.InteropServices;
17 namespace System.Resources
20 public class ResourceSet : IDisposable
28 protected IResourceReader Reader;
29 protected Hashtable Table;
32 protected ResourceSet () {}
34 public ResourceSet (IResourceReader reader)
37 throw new ArgumentNullException ("The reader is null.");
41 public ResourceSet (Stream stream)
44 throw new ArgumentNullException("stream is null");
48 throw new ArgumentException("stream is not readable");
51 Reader = new ResourceReader (stream);
54 public ResourceSet (String fileName)
57 throw new ArgumentNullException("filename is null");
60 Reader = new ResourceReader (fileName);
63 public virtual void Close ()
73 protected virtual void Dispose (bool disposing)
85 public virtual Type GetDefaultReader ()
87 return (typeof (ResourceReader));
89 public virtual Type GetDefaultWriter ()
91 return (typeof (ResourceWriter));
97 public virtual IDictionaryEnumerator GetEnumerator ()
101 return Table.GetEnumerator();
104 IEnumerator IEnumerable.GetEnumerator ()
106 return this.GetEnumerator ();
111 public virtual object GetObject (string name)
114 throw new ArgumentNullException ("The name parameter is null.");
116 throw new InvalidOperationException ("The ResourceSet has been closed.");
125 public virtual object GetObject (string name, bool ignoreCase)
128 throw new ArgumentNullException ("The name parameter is null.");
130 throw new InvalidOperationException ("ResourceSet has been closed.");
135 foreach (DictionaryEntry de in Table) {
136 string key = (string) de.Key;
137 if (String.Compare (key, name, true, CultureInfo.InvariantCulture) == 0)
145 public virtual string GetString (string name)
147 Object o = GetObject (name);
152 throw new InvalidOperationException("Not a string");
155 public virtual string GetString (string name, bool ignoreCase)
157 Object o = GetObject (name, ignoreCase);
162 throw new InvalidOperationException("Not a string");
165 protected virtual void ReadResources ()
167 IDictionaryEnumerator i = Reader.GetEnumerator();
170 Table = new Hashtable ();
173 while (i.MoveNext ())
174 Table.Add (i.Key, i.Value);