merge -r 60814:60815
[mono.git] / mcs / class / System / System.ComponentModel / ComponentResourceManager.cs
1 //
2 // System.ComponentModel.ComponentResourceManager.cs
3 //
4 // Author:
5 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
6 //
7 // (C) 2003 Andreas Nahr
8 //
9 //
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 #if NET_1_1
33
34 using System;
35 using System.Resources;
36 using System.Globalization;
37 using System.Collections;
38 using System.Reflection;
39
40 namespace System.ComponentModel {
41
42         public class ComponentResourceManager : ResourceManager
43         {
44                 public ComponentResourceManager ()
45                 {
46                 }
47
48                 public ComponentResourceManager (Type t)
49                         : base (t)
50                 {
51                 }
52
53                 public void ApplyResources (object value, string objectName)
54                 {
55                         ApplyResources (value, objectName, System.Threading.Thread.CurrentThread.CurrentCulture);
56                 }
57
58                 public virtual void ApplyResources (object value, string objectName, CultureInfo culture)
59                 {
60                         string objKey = objectName + ".";
61                         Type type = value.GetType ();
62                         
63                         ResourceSet rset = GetResourceSet (culture, true, true);
64                         foreach (DictionaryEntry di in rset)
65                         {
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);
72                                 }
73                         }
74                         rset.Close ();
75                 }
76         }
77 }
78
79 #endif