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
10 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
34 using System.Globalization;
35 using System.Runtime.InteropServices;
36 using System.Security.Permissions;
38 namespace System.Resources
41 public class ResourceSet : IDisposable
49 protected IResourceReader Reader;
50 protected Hashtable Table;
53 protected ResourceSet () {}
55 public ResourceSet (IResourceReader reader)
58 throw new ArgumentNullException ("The reader is null.");
62 [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
63 public ResourceSet (Stream stream)
66 throw new ArgumentNullException("stream is null");
70 throw new ArgumentException("stream is not readable");
73 Reader = new ResourceReader (stream);
76 public ResourceSet (String fileName)
79 throw new ArgumentNullException("filename is null");
82 Reader = new ResourceReader (fileName);
85 public virtual void Close ()
95 protected virtual void Dispose (bool disposing)
107 public virtual Type GetDefaultReader ()
109 return (typeof (ResourceReader));
111 public virtual Type GetDefaultWriter ()
113 return (typeof (ResourceWriter));
119 public virtual IDictionaryEnumerator GetEnumerator ()
123 return Table.GetEnumerator();
126 IEnumerator IEnumerable.GetEnumerator ()
128 return this.GetEnumerator ();
133 public virtual object GetObject (string name)
136 throw new ArgumentNullException ("The name parameter is null.");
138 throw new InvalidOperationException ("The ResourceSet has been closed.");
147 public virtual object GetObject (string name, bool ignoreCase)
150 throw new ArgumentNullException ("The name parameter is null.");
152 throw new InvalidOperationException ("ResourceSet has been closed.");
157 foreach (DictionaryEntry de in Table) {
158 string key = (string) de.Key;
159 if (String.Compare (key, name, true, CultureInfo.InvariantCulture) == 0)
167 public virtual string GetString (string name)
169 Object o = GetObject (name);
174 throw new InvalidOperationException("Not a string");
177 public virtual string GetString (string name, bool ignoreCase)
179 Object o = GetObject (name, ignoreCase);
184 throw new InvalidOperationException("Not a string");
187 protected virtual void ReadResources ()
190 throw new InvalidOperationException ("ResourceSet is closed.");
192 IDictionaryEnumerator i = Reader.GetEnumerator();
195 Table = new Hashtable ();
198 while (i.MoveNext ())
199 Table.Add (i.Key, i.Value);