1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Resources
17 using System
.Collections
;
18 using System
.Globalization
;
19 using System
.Resources
;
22 /// Simple facade that provides the IResource interface to a
23 /// ResourceManager instance.
25 public class ResourceFacade
: IResource
27 private readonly ResourceManager resourceManager
;
28 private readonly CultureInfo cultureInfo
;
31 /// Initializes a new instance of the <see cref="ResourceFacade"/> class.
33 /// <param name="resourceManager">The resource manager.</param>
34 /// <param name="cultureInfo">The culture info.</param>
35 public ResourceFacade(ResourceManager resourceManager
, CultureInfo cultureInfo
)
37 this.resourceManager
= resourceManager
;
38 this.cultureInfo
= cultureInfo
;
42 /// Returns the object linked to the specific key.
44 /// <param name="key"></param>
45 /// <returns></returns>
46 public object GetObject(string key
)
48 return resourceManager
.GetObject(key
, cultureInfo
);
52 /// Returns the object linked to the specific key as a string.
54 /// <param name="key"></param>
55 /// <returns></returns>
56 public string GetString(string key
)
58 return resourceManager
.GetString(key
, cultureInfo
);
62 /// Returns the object linked to the specific key.
65 public object this[string key
]
67 get { return resourceManager.GetObject(key, cultureInfo); }
71 /// Returns an enumerator that iterates through a collection.
74 /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
76 public IEnumerator
GetEnumerator()
78 return resourceManager
79 .GetResourceSet(cultureInfo
, true, true)