Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ResourceSet.cs « System.Resources « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d96df5e5fa20e454c329d2455daa050fd3d5d59d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// System.Resources.ResourceSet.cs
//
// Author:
//	Duncan Mak (duncan@ximian.com)
//
// (C) 2001 Ximian, Inc.		http://www.ximian.com
//

using System.Collections;
using System.IO;

namespace System.Resources
{
	[Serializable]
	public class ResourceSet : IDisposable
	{

		protected IResourceReader Reader;
		protected Hashtable Table;

		// Constructors
		protected ResourceSet () {}
		public ResourceSet (IResourceReader reader)
		{
			if (reader == null)
				throw new ArgumentNullException ("The reader is null.");
			Reader = reader;
		}

		public ResourceSet (Stream stream)
		{
			Reader = new ResourceReader (stream);
		}

		public ResourceSet (String fileName)
		{
			Reader = new ResourceReader (fileName);
		}

		public virtual void Close ()
		{
			Dispose (true);
		}

		public void Dispose()
		{
			Dispose (true);
		}

		protected virtual void Dispose (bool disposing)
		{
			if (disposing) {
				Reader = null;
				Table = null;
			} 
		}

		public virtual Type GetDefaultReader ()
		{
			return (typeof (ResourceReader));
		} 
		public virtual Type GetDefaultWriter ()
		{
			return (typeof (ResourceWriter));
		}

		public virtual object GetObject (string name)
		{
			if (name == null)
				throw new ArgumentNullException ("The name parameter is null.");
			if (Reader == null)
				throw new InvalidOperationException ("The ResourceSet has been closed.");
			if (Table == null) {
				ReadResources ();
				return Table[name];
			} else 
				return Table[name];
		}
		public virtual object GetObject (string name, bool ignoreCase)
		{
			if (name == null)
				throw new ArgumentNullException ("The name parameter is null.");
			if (Reader == null)
				throw new InvalidOperationException ("ResourceSet has been closed.");
			if (Table == null)
				ReadResources ();
			if (ignoreCase) {
				foreach (DictionaryEntry de in Table) {
					string key = (string) de.Key;
					if (String.Compare (key, name, true) == 0)
						return de.Value;
				}
				return null;
			} else
				return Table[name];
		}

		public virtual string GetString (string name)
		{
			Object o = GetObject (name);
			if (o is string)
				return (string) o;
			return null;
		}

		public virtual string GetString (string name, bool ignoreCase)
		{
			Object o = GetObject (name, ignoreCase);
			if (o is string)
				return (string) o;
			return null;
		}

		protected virtual void ReadResources ()
		{
			IDictionaryEnumerator i = Reader.GetEnumerator();

			if (Table == null)
				Table = new Hashtable ();
			i.Reset ();

			while (i.MoveNext ()) 
				Table.Add (i.Key, i.Value);
		}
	}
}