我正在通过实现ICustomTypeDescriptor
来自定义对象类型在PropertyGrid
中的显示方式。我允许用户创建自己的自定义属性,这些属性存储在单个字典的键和值中。我可以为这些值创建所有PropertyDescriptors
,并在属性网格中查看它们。但是,我还想显示所有默认属性,否则在通过反射填充PropertyGrid
而不是我的覆盖ICustomTypeDescriptor.GetProperties
方法时将显示此属性。获取某个类型的默认PropertyDescriptors
现在我知道如何获得对象的类型,然后GetProperties()
,但是这会返回一个PropertyInfo
而不是ProperyDescriptor
的数组。那么,如何将PropertyInfo
类型的对象转换为PropertyDescriptor
对象,以将其包含到我的收藏夹中,并使用自定义PropertyDescriptors
?
//gets the local intrinsic properties of the object
Type thisType = this.GetType();
PropertyInfo[] thisProps = thisType.GetProperties();
//this line obviously doesn't work because the propertydescriptor
//collection needs an array of PropertyDescriptors not PropertyInfo
PropertyDescriptorCollection propCOl =
new PropertyDescriptorCollection(thisProps);
非常感谢! – Ross 2017-11-17 00:29:17