New test.
[mono.git] / mcs / class / System / System.ComponentModel / DerivedPropertyDescriptor.cs
1 //
2 // System.ComponentModel.DerivedPropertyDescriptor
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 using System;
31 using System.Reflection;
32
33 namespace System.ComponentModel
34 {
35         class DerivedPropertyDescriptor : PropertyDescriptor
36         {
37                 bool readOnly;
38                 Type componentType;
39                 Type propertyType;
40                 PropertyInfo prop;
41
42                 protected DerivedPropertyDescriptor (string name, Attribute [] attrs)
43                         : base (name, attrs)
44                 {
45                 }
46
47                 public DerivedPropertyDescriptor (string name, Attribute [] attrs, int dummy)
48                         : this (name, attrs)
49                 {
50                 }
51
52                 public void SetReadOnly (bool value)
53                 {
54                         readOnly = value;
55                 }
56                 
57                 public void SetComponentType (Type type)
58                 {
59                         componentType = type;
60                 }
61
62                 public void SetPropertyType (Type type)
63                 {
64                         propertyType = type;
65                 }
66
67                 public override object GetValue (object component)
68                 {
69                         if (prop == null)
70                                 prop = componentType.GetProperty (Name);
71
72                         return prop.GetValue (component, null);
73                 }
74
75                 public override void SetValue(object component, object value) {
76                         
77                         if (prop == null)
78                                 prop = componentType.GetProperty (Name);
79
80                         prop.SetValue (component, value, null);
81                         // FIXME: EventArgs might be differen type.
82                         OnValueChanged (component, new PropertyChangedEventArgs (Name));
83                 }
84
85                 [MonoTODO]
86                 public override void ResetValue(object component) {
87
88                         throw new NotImplementedException ();
89                 }
90
91                 [MonoTODO]
92                 public override bool CanResetValue(object component) {
93
94                         throw new NotImplementedException ();
95                 }
96
97                 [MonoTODO]
98                 public override bool ShouldSerializeValue(object component) {
99
100                         throw new NotImplementedException ();
101                 }
102
103                 public override Type ComponentType
104                 {
105                         get {
106                                 return componentType;
107                         }
108
109                 }
110
111                 public override bool IsReadOnly
112                 {
113                         get {
114                                 return readOnly;
115                                 
116                         }
117
118                 }
119
120                 public override Type PropertyType
121                 {
122                         get {
123                                 return propertyType;
124                         }
125
126                 }
127         }
128 }
129