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

ResourceManager.cs « System.Resources « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c592c2d5d2ce07500cbf0936ddb97dfd48736054 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//	
// System.Resources.ResourceManager.cs
//
// Author:
//	Duncan Mak (duncan@ximian.com)
//
// 2001 (C) Ximian, Inc. http://www.ximian.com
//

using System.Collections;
using System.Reflection;
using System.Globalization;

namespace System.Resources
{
	[Serializable]
	public class ResourceManager
	{
		public static readonly int HeaderVersionNumber;
		// public static readonly int MagicNumber = 0xBEEFCACE;

		protected string BaseNameField;
		protected Assembly MainAssembly;
		protected Hashtable ResourceSets;
		
		private bool ignoreCase;
		private Type resourceSetType;
		
		// constructors
		protected ResourceManager () {}
		
		public ResourceManager (Type resourceSource)
		{
			if (resourceSource == null)
				throw new ArgumentNullException ("resourceSource is null.");
			
			BaseNameField = resourceSource.FullName;
			MainAssembly = resourceSource.Assembly;
			
			ignoreCase = false;
			resourceSetType = resourceSource;
		}
		
		public ResourceManager (string baseName, Assembly assembly)
		{
			if (baseName == null || assembly == null)
				throw new ArgumentNullException ("The arguments are null.");
			
			BaseNameField = baseName;
			MainAssembly = assembly;
			ignoreCase = false;
			resourceSetType = typeof (ResourceSet);
		}
			 
		public ResourceManager (string baseName, Assembly assembly, Type usingResourceSet)
		{
			if (baseName == null || assembly == null)
				throw new ArgumentNullException ("The arguments are null.");
			
			BaseNameField = baseName;
			MainAssembly = assembly;
			
			if (usingResourceSet == null) // defaults resourceSet type.
				resourceSetType = typeof (ResourceSet);
			else {
				if (!usingResourceSet.IsSubclassOf (typeof (ResourceSet)))
					throw new ArgumentException ("Type must be from ResourceSet.");
				
			}
		}
		
		[MonoTODO]
		public static ResourceManager CreateFileBasedResourceManager (string baseName,
						      string resourceDir, Type usingResourceSet)
		{
			return null;
		}

		public virtual string BaseName
		{
			get { return BaseNameField; }
		}

		public virtual bool IgnoreCase
		{
			get { return ignoreCase; }
			set { ignoreCase = value; }
		}

		public virtual Type ResourceSetType
		{
			get { return resourceSetType; }
		}
			 
		[MonoTODO]
		public virtual ResourceSet GetResourceSet (CultureInfo culture,
					   bool createIfNotExists, bool tryParents)
			
		{
			if (culture == null)
				throw new ArgumentNullException ("CultureInfo is a null reference.");
			return null;
		}
		
		[MonoTODO]
		public virtual string GetString (string name)
		{
			if (name == null)
				throw new ArgumentNullException ("Name is null.");
			if (ResourceSets.Contains (name)) {
				if (!(ResourceSets[name] is string))
					throw new InvalidOperationException ("The resource is " +
									     "not a string.");
				return ResourceSets[name].ToString();
			}
			return null;	
		}

		[MonoTODO]
		public virtual string GetString (string name, CultureInfo culture)
		{
				 if (name == null)
					 throw new ArgumentNullException ("Name is null.");
				 return null;
		}

		protected virtual string GetResourceFileName (CultureInfo culture)
		{
			return culture.Name + ".resources";
		}

		[MonoTODO]
		protected virtual ResourceSet InternalGetResourceSet (CultureInfo culture,
						   bool Createifnotexists, bool tryParents)
			 {
				 return null;
			 }
		   
		public virtual void ReleaseAllResources ()
		{
			foreach (ResourceSet r in ResourceSets)
				r.Close();
		}

		protected static CultureInfo GetNeutralResourcesLanguage (Assembly a)
		{
			foreach (Attribute attribute in a.GetCustomAttributes (false)) {
				if (attribute is NeutralResourcesLanguageAttribute)
					return new CultureInfo ((attribute as NeutralResourcesLanguageAttribute).CultureName);
			}
			return null;
		}

		protected static Version GetSatelliteContractVersion (Assembly a)
		{
			foreach (Attribute attribute in a.GetCustomAttributes (false)) {
				if (attribute is SatelliteContractVersionAttribute)
					return new Version ((attribute as SatelliteContractVersionAttribute).Version);
			}
			return null; // return null if no version was found.
		}
	}
}