C# 获取类型的默认PropertyDescriptor

C# 获取类型的默认PropertyDescriptor,c#,propertygrid,propertyinfo,propertydescriptor,C#,Propertygrid,Propertyinfo,Propertydescriptor,我正在通过实现ICustomTypeDescriptor自定义对象类型在PropertyGrid中的显示方式。我允许用户创建自己的自定义属性,这些属性存储在一个键和值字典中。我能够为这些值创建所有的PropertyDescriptor,并在属性网格中查看它们。但是,我还想显示所有默认属性,如果PropertyGrid是通过反射而不是我的overrideICustomTypeDescriptor.GetProperties方法填充的,则会显示这些属性 现在我知道了如何获取对象的类型,然后是GetP

我正在通过实现
ICustomTypeDescriptor
自定义对象类型在
PropertyGrid
中的显示方式。我允许用户创建自己的自定义属性,这些属性存储在一个键和值字典中。我能够为这些值创建所有的
PropertyDescriptor
,并在属性网格中查看它们。但是,我还想显示所有默认属性,如果
PropertyGrid
是通过反射而不是我的override
ICustomTypeDescriptor.GetProperties
方法填充的,则会显示这些属性

现在我知道了如何获取对象的类型,然后是
GetProperties()
,但这将返回一个
PropertyInfo
数组,而不是
propertyDescriptor
。那么,如何将类型的
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);
顺便说一下:这不包括您的
ICustomTypeDescriptor
自定义,但包括通过
TypeDescriptionProvider
进行的任何自定义

(编辑) 另一方面,您还可以通过提供比
ICustomTypeDescriptor
TypeDescriptionProvider
简单得多的
TypeConverter
来调整
PropertyGrid
,例如:

[TypeConverter(typeof(FooConverter))]
class Foo { }

class FooConverter : ExpandableObjectConverter
{
    public override PropertyDescriptorCollection GetProperties(
       ITypeDescriptorContext context, object value, Attribute[] attributes)
    {
        // your code here, perhaps using base.GetPoperties(
        //    context, value, attributes);
    }
}
[TypeConverter(typeof(FooConverter))]
class Foo { }

class FooConverter : ExpandableObjectConverter
{
    public override PropertyDescriptorCollection GetProperties(
       ITypeDescriptorContext context, object value, Attribute[] attributes)
    {
        // your code here, perhaps using base.GetPoperties(
        //    context, value, attributes);
    }
}