1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
using System.ComponentModel;
#region Referenced Description Attribute
public class ReferencedDescriptionAttribute : DescriptionAttribute
{
public ReferencedDescriptionAttribute(Type referencedType, string propertyName)
{
string result = "Referenced description not available";
// gets the properties of the referenced type
PropertyDescriptorCollection properties
= TypeDescriptor.GetProperties(referencedType);
if (properties != null) {
// gets a PropertyDescriptor to the specific property.
PropertyDescriptor property = properties[propertyName];
if (property != null) {
// gets the attributes of the required property
AttributeCollection attributes = property.Attributes;
// Gets the description attribute from the collection.
DescriptionAttribute descript
= (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
// register the referenced description
if (!String.IsNullOrEmpty(descript.Description))
result = descript.Description;
}
}
DescriptionValue = result;
}
}
#endregion
|