我正在PropertyGrid通过实现来自定义对象类型在 a 中的显示方式ICustomTypeDescriptor。我允许用户创建自己的自定义属性,这些属性存储在单个键和值字典中。我能够PropertyDescriptors为这些值创建所有值并在属性网格中查看它们。但是,我还想显示所有默认属性,如果PropertyGrid通过反射而不是我的覆盖ICustomTypeDescriptor.GetProperties方法填充这些默认属性。
现在我知道如何获取对象的类型,然后GetProperties()是 ,但这会返回一个PropertyInfonot的数组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);