Assuming the AssociatedMetadataTypeTypeDescriptionProvider
for your class has been registered correctly, the System.ComponentModel.TypeDescriptor
class will honour the attributes from your metadata class.
Add this somewhere near the start of your program:
TypeDescriptor.AddProvider(
new AssociatedMetadataTypeTypeDescriptionProvider(typeof(person)),
typeof(person));
Then access the properties:
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(person));
PropertyDescriptor prop = properties["Name"];
string displayName = prop.DisplayName;
Alternatively, you can use the AssociatedMetadataTypeTypeDescriptionProvider
class directly:
var provider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(person));
ICustomTypeDescriptor typeDescriptor = provider.GetTypeDescriptor(typeof(person), null);
PropertyDescriptorCollection properties = typeDescriptor.GetProperties();
PropertyDescriptor prop = properties["Name"];
string displayName = prop.DisplayName;
NB: Your DisplayName
attribute doesn't currently change the display name, so you won't see any difference. Change the value passed to the attribute constructor to see that the type descriptor is working.