OLD | NEW |
| (Empty) |
1 /// Copyright (c) Microsoft Corporation. All rights reserved. | |
2 | |
3 using System; | |
4 using System.Collections; | |
5 using System.ComponentModel; | |
6 | |
7 namespace Microsoft.VisualStudio.Project | |
8 { | |
9 /// <summary> | |
10 /// The purpose of DesignPropertyDescriptor is to allow us to customize
the | |
11 /// display name of the property in the property grid. None of the CLR | |
12 /// implementations of PropertyDescriptor allow you to change the Displa
yName. | |
13 /// </summary> | |
14 public class DesignPropertyDescriptor : PropertyDescriptor | |
15 { | |
16 private string displayName; // Custom display name | |
17 private PropertyDescriptor property; // Base property descrip
tor | |
18 private Hashtable editors = new Hashtable(); // Type -> editor i
nstance | |
19 private TypeConverter converter; | |
20 | |
21 | |
22 /// <summary> | |
23 /// Delegates to base. | |
24 /// </summary> | |
25 public override string DisplayName | |
26 { | |
27 get | |
28 { | |
29 return this.displayName; | |
30 } | |
31 } | |
32 | |
33 /// <summary> | |
34 /// Delegates to base. | |
35 /// </summary> | |
36 public override Type ComponentType | |
37 { | |
38 get | |
39 { | |
40 return this.property.ComponentType; | |
41 } | |
42 } | |
43 | |
44 /// <summary> | |
45 /// Delegates to base. | |
46 /// </summary> | |
47 public override bool IsReadOnly | |
48 { | |
49 get | |
50 { | |
51 return this.property.IsReadOnly; | |
52 } | |
53 } | |
54 | |
55 /// <summary> | |
56 /// Delegates to base. | |
57 /// </summary> | |
58 public override Type PropertyType | |
59 { | |
60 get | |
61 { | |
62 return this.property.PropertyType; | |
63 } | |
64 } | |
65 | |
66 | |
67 /// <summary> | |
68 /// Delegates to base. | |
69 /// </summary> | |
70 public override object GetEditor(Type editorBaseType) | |
71 { | |
72 object editor = this.editors[editorBaseType]; | |
73 if(editor == null) | |
74 { | |
75 for(int i = 0; i < this.Attributes.Count; i++) | |
76 { | |
77 EditorAttribute attr = Attributes[i] as
EditorAttribute; | |
78 if(attr == null) | |
79 { | |
80 continue; | |
81 } | |
82 Type editorType = Type.GetType(attr.Edit
orBaseTypeName); | |
83 if(editorBaseType == editorType) | |
84 { | |
85 Type type = GetTypeFromNamePrope
rty(attr.EditorTypeName); | |
86 if(type != null) | |
87 { | |
88 editor = CreateInstance(
type); | |
89 this.editors[type] = edi
tor; // cache it | |
90 break; | |
91 } | |
92 } | |
93 } | |
94 } | |
95 return editor; | |
96 } | |
97 | |
98 | |
99 /// <summary> | |
100 /// Return type converter for property | |
101 /// </summary> | |
102 public override TypeConverter Converter | |
103 { | |
104 get | |
105 { | |
106 if(converter == null) | |
107 { | |
108 PropertyPageTypeConverterAttribute attr
= (PropertyPageTypeConverterAttribute)Attributes[typeof(PropertyPageTypeConverte
rAttribute)]; | |
109 if(attr != null && attr.ConverterType !=
null) | |
110 { | |
111 converter = (TypeConverter)Creat
eInstance(attr.ConverterType); | |
112 } | |
113 | |
114 if(converter == null) | |
115 { | |
116 converter = TypeDescriptor.GetCo
nverter(this.PropertyType); | |
117 } | |
118 } | |
119 return converter; | |
120 } | |
121 } | |
122 | |
123 | |
124 | |
125 /// <summary> | |
126 /// Convert name to a Type object. | |
127 /// </summary> | |
128 public virtual Type GetTypeFromNameProperty(string typeName) | |
129 { | |
130 return Type.GetType(typeName); | |
131 } | |
132 | |
133 | |
134 /// <summary> | |
135 /// Delegates to base. | |
136 /// </summary> | |
137 public override bool CanResetValue(object component) | |
138 { | |
139 bool result = this.property.CanResetValue(component); | |
140 return result; | |
141 } | |
142 | |
143 /// <summary> | |
144 /// Delegates to base. | |
145 /// </summary> | |
146 public override object GetValue(object component) | |
147 { | |
148 object value = this.property.GetValue(component); | |
149 return value; | |
150 } | |
151 | |
152 /// <summary> | |
153 /// Delegates to base. | |
154 /// </summary> | |
155 public override void ResetValue(object component) | |
156 { | |
157 this.property.ResetValue(component); | |
158 } | |
159 | |
160 /// <summary> | |
161 /// Delegates to base. | |
162 /// </summary> | |
163 public override void SetValue(object component, object value) | |
164 { | |
165 this.property.SetValue(component, value); | |
166 } | |
167 | |
168 /// <summary> | |
169 /// Delegates to base. | |
170 /// </summary> | |
171 public override bool ShouldSerializeValue(object component) | |
172 { | |
173 bool result = this.property.ShouldSerializeValue(compone
nt); | |
174 return result; | |
175 } | |
176 | |
177 /// <summary> | |
178 /// Constructor. Copy the base property descriptor and also hol
d a pointer | |
179 /// to it for calling its overridden abstract methods. | |
180 /// </summary> | |
181 public DesignPropertyDescriptor(PropertyDescriptor prop) | |
182 : base(prop) | |
183 { | |
184 this.property = prop; | |
185 | |
186 DisplayNameAttribute attr = prop.Attributes[typeof(Displ
ayNameAttribute)] as DisplayNameAttribute; | |
187 | |
188 if(attr != null) | |
189 { | |
190 this.displayName = attr.DisplayName; | |
191 } | |
192 else | |
193 { | |
194 this.displayName = prop.Name; | |
195 } | |
196 } | |
197 } | |
198 } | |
OLD | NEW |