0
|
1 using System;
|
|
2 using System.ComponentModel;
|
|
3
|
|
4 using BLToolkit.Reflection;
|
|
5
|
|
6 namespace BLToolkit.ComponentModel
|
|
7 {
|
|
8 public class ObjectHolder : ICustomTypeDescriptor
|
|
9 {
|
|
10 public ObjectHolder(object obj, ObjectBinder objectBinder)
|
|
11 {
|
|
12 _object = obj;
|
|
13 _originalProperties = ((ITypedList)objectBinder).GetItemProperties(null);
|
|
14 }
|
|
15
|
|
16 private readonly PropertyDescriptorCollection _originalProperties;
|
|
17 private PropertyDescriptorCollection _customProperties;
|
|
18
|
|
19 private readonly object _object;
|
|
20 public object Object
|
|
21 {
|
|
22 get { return _object; }
|
|
23 }
|
|
24
|
|
25 private ICustomTypeDescriptor _customTypeDescriptor;
|
|
26 private ICustomTypeDescriptor CustomTypeDescriptor
|
|
27 {
|
|
28 get
|
|
29 {
|
|
30 if (_customTypeDescriptor == null)
|
|
31 {
|
|
32 _customTypeDescriptor = _object is ICustomTypeDescriptor?
|
|
33 (ICustomTypeDescriptor)_object:
|
|
34 TypeAccessor.GetCustomTypeDescriptor(_object.GetType());
|
|
35 }
|
|
36
|
|
37 return _customTypeDescriptor;
|
|
38 }
|
|
39 }
|
|
40
|
|
41 #region ICustomTypeDescriptor Members
|
|
42
|
|
43 AttributeCollection ICustomTypeDescriptor.GetAttributes()
|
|
44 {
|
|
45 return CustomTypeDescriptor.GetAttributes();
|
|
46 }
|
|
47
|
|
48 string ICustomTypeDescriptor.GetClassName()
|
|
49 {
|
|
50 return CustomTypeDescriptor.GetClassName();
|
|
51 }
|
|
52
|
|
53 string ICustomTypeDescriptor.GetComponentName()
|
|
54 {
|
|
55 return CustomTypeDescriptor.GetComponentName();
|
|
56 }
|
|
57
|
|
58 TypeConverter ICustomTypeDescriptor.GetConverter()
|
|
59 {
|
|
60 return CustomTypeDescriptor.GetConverter();
|
|
61 }
|
|
62
|
|
63 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
|
|
64 {
|
|
65 return CustomTypeDescriptor.GetDefaultEvent();
|
|
66 }
|
|
67
|
|
68 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
|
|
69 {
|
|
70 return CustomTypeDescriptor.GetDefaultProperty();
|
|
71 }
|
|
72
|
|
73 object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
|
|
74 {
|
|
75 return CustomTypeDescriptor.GetEditor(editorBaseType);
|
|
76 }
|
|
77
|
|
78 EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
|
|
79 {
|
|
80 return CustomTypeDescriptor.GetEvents(attributes);
|
|
81 }
|
|
82
|
|
83 EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
|
|
84 {
|
|
85 return CustomTypeDescriptor.GetEvents();
|
|
86 }
|
|
87
|
|
88 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
|
|
89 {
|
|
90 if (_customProperties == null)
|
|
91 {
|
|
92 PropertyDescriptor[] properties = new PropertyDescriptor[_originalProperties.Count];
|
|
93
|
|
94 for (int i = 0; i < properties.Length; i++)
|
|
95 {
|
|
96 properties[i] = new ObjectPropertyDescriptor(_originalProperties[i]);
|
|
97 }
|
|
98
|
|
99 _customProperties = new PropertyDescriptorCollection(properties);
|
|
100 }
|
|
101
|
|
102 return _customProperties;
|
|
103 }
|
|
104
|
|
105 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
|
|
106 {
|
|
107 return ((ICustomTypeDescriptor)this).GetProperties(null);
|
|
108 }
|
|
109
|
|
110 object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
|
|
111 {
|
|
112 return CustomTypeDescriptor.GetPropertyOwner(pd);
|
|
113 }
|
|
114
|
|
115 #endregion
|
|
116
|
|
117 #region ObjectPropertyDescriptor
|
|
118
|
|
119 class ObjectPropertyDescriptor : PropertyDescriptorWrapper
|
|
120 {
|
|
121 public ObjectPropertyDescriptor(PropertyDescriptor pd)
|
|
122 : base(pd)
|
|
123 {
|
|
124 }
|
|
125
|
|
126 public override object GetValue(object component)
|
|
127 {
|
|
128 return base.GetValue(((ObjectHolder)component).Object);
|
|
129 }
|
|
130
|
|
131 public override void SetValue(object component, object value)
|
|
132 {
|
|
133 base.SetValue(((ObjectHolder)component).Object, value);
|
|
134 }
|
|
135 }
|
|
136
|
|
137 #endregion
|
|
138 }
|
|
139 }
|