I propose a change to the PropertyGrid to allow the use of an associated MetadataType class to define attributes such as DisplayName. This is useful when dealing with auto generated partial classes.
The change is minor, but it does add a dependency on System.ComponentModel.DataAnnotations. The full file is attached, but the change is to use AssociatedMetadataTypeTypeDescriptionProvider to retrieve the PropertyDescriptors.
```
protected static List<PropertyDescriptor> GetPropertyDescriptors( object instance )
{
PropertyDescriptorCollection descriptors;
TypeConverter tc = TypeDescriptor.GetConverter( instance );
if( tc == null || !tc.GetPropertiesSupported() )
{
if (instance is ICustomTypeDescriptor)
descriptors = ((ICustomTypeDescriptor)instance).GetProperties();
else
// descriptors = TypeDescriptor.GetProperties( instance.GetType() );
{
AssociatedMetadataTypeTypeDescriptionProvider provider = new AssociatedMetadataTypeTypeDescriptionProvider(instance.GetType());
descriptors = provider.GetTypeDescriptor(instance).GetProperties();
}
}
else
{
descriptors = tc.GetProperties( instance );
}
return ( descriptors != null )
? descriptors.Cast<PropertyDescriptor>().ToList()
: null;
}
```
The change is minor, but it does add a dependency on System.ComponentModel.DataAnnotations. The full file is attached, but the change is to use AssociatedMetadataTypeTypeDescriptionProvider to retrieve the PropertyDescriptors.
```
protected static List<PropertyDescriptor> GetPropertyDescriptors( object instance )
{
PropertyDescriptorCollection descriptors;
TypeConverter tc = TypeDescriptor.GetConverter( instance );
if( tc == null || !tc.GetPropertiesSupported() )
{
if (instance is ICustomTypeDescriptor)
descriptors = ((ICustomTypeDescriptor)instance).GetProperties();
else
// descriptors = TypeDescriptor.GetProperties( instance.GetType() );
{
AssociatedMetadataTypeTypeDescriptionProvider provider = new AssociatedMetadataTypeTypeDescriptionProvider(instance.GetType());
descriptors = provider.GetTypeDescriptor(instance).GetProperties();
}
}
else
{
descriptors = tc.GetProperties( instance );
}
return ( descriptors != null )
? descriptors.Cast<PropertyDescriptor>().ToList()
: null;
}
```