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
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:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
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
;
37 using System
.Globalization
;
38 using System
.Runtime
.InteropServices
;
40 namespace System
.Resources
43 public class ResourceSet
: IDisposable
51 protected IResourceReader Reader
;
52 protected Hashtable Table
;
55 protected ResourceSet () {}
57 public ResourceSet (IResourceReader reader
)
60 throw new ArgumentNullException ("The reader is null.");
64 public ResourceSet (Stream stream
)
67 throw new ArgumentNullException("stream is null");
71 throw new ArgumentException("stream is not readable");
74 Reader
= new ResourceReader (stream
);
77 public ResourceSet (String fileName
)
80 throw new ArgumentNullException("filename is null");
83 Reader
= new ResourceReader (fileName
);
86 public virtual void Close ()
96 protected virtual void Dispose (bool disposing
)
108 public virtual Type
GetDefaultReader ()
110 return (typeof (ResourceReader
));
112 public virtual Type
GetDefaultWriter ()
114 return (typeof (ResourceWriter
));
120 public virtual IDictionaryEnumerator
GetEnumerator ()
124 return Table
.GetEnumerator();
127 IEnumerator IEnumerable
.GetEnumerator ()
129 return this.GetEnumerator ();
134 public virtual object GetObject (string name
)
137 throw new ArgumentNullException ("The name parameter is null.");
139 throw new InvalidOperationException ("The ResourceSet has been closed.");
148 public virtual object GetObject (string name
, bool ignoreCase
)
151 throw new ArgumentNullException ("The name parameter is null.");
153 throw new InvalidOperationException ("ResourceSet has been closed.");
158 foreach (DictionaryEntry de
in Table
) {
159 string key
= (string) de
.Key
;
160 if (String
.Compare (key
, name
, true, CultureInfo
.InvariantCulture
) == 0)
168 public virtual string GetString (string name
)
170 Object o
= GetObject (name
);
175 throw new InvalidOperationException("Not a string");
178 public virtual string GetString (string name
, bool ignoreCase
)
180 Object o
= GetObject (name
, ignoreCase
);
185 throw new InvalidOperationException("Not a string");
188 protected virtual void ReadResources ()
191 throw new InvalidOperationException ("ResourceSet is closed.");
193 IDictionaryEnumerator i
= Reader
.GetEnumerator();
196 Table
= new Hashtable ();
199 while (i
.MoveNext ())
200 Table
.Add (i
.Key
, i
.Value
);