2 // System.ComponentModel.ComponentResourceManager.cs
5 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 // (C) 2003 Andreas Nahr
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.
35 using System
.Resources
;
36 using System
.Globalization
;
37 using System
.Collections
;
38 using System
.Reflection
;
40 namespace System
.ComponentModel
{
42 public class ComponentResourceManager
: ResourceManager
44 public ComponentResourceManager ()
48 public ComponentResourceManager (Type t
)
53 public void ApplyResources (object value, string objectName
)
55 ApplyResources (value, objectName
, System
.Threading
.Thread
.CurrentThread
.CurrentCulture
);
58 public virtual void ApplyResources (object value, string objectName
, CultureInfo culture
)
60 string objKey
= objectName
+ ".";
61 Type type
= value.GetType ();
63 ResourceSet rset
= GetResourceSet (culture
, true, true);
64 foreach (DictionaryEntry di
in rset
)
66 string key
= di
.Key
as string;
67 if (key
.StartsWith (objKey
)) {
68 key
= key
.Substring (objKey
.Length
);
69 PropertyInfo pi
= type
.GetProperty (key
);
70 if (pi
!= null && pi
.CanWrite
)
71 pi
.SetValue (value, Convert
.ChangeType (di
.Value
, pi
.PropertyType
), null);