Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ICustomTypeDescriptor、TypeDescriptionProvider、TypeConverter和UITypeEditor_C#_Propertygrid_Typeconverter_Uitypeeditor_Customtypedescriptor - Fatal编程技术网

C# ICustomTypeDescriptor、TypeDescriptionProvider、TypeConverter和UITypeEditor

C# ICustomTypeDescriptor、TypeDescriptionProvider、TypeConverter和UITypeEditor,c#,propertygrid,typeconverter,uitypeeditor,customtypedescriptor,C#,Propertygrid,Typeconverter,Uitypeeditor,Customtypedescriptor,我试图全面了解如何使用ICustomTypeDescriptor、TypeDescriptionProvider、TypeConverter和UITypeEditor来更改PropertyGrid的显示方式以及与对象的接口 有人能告诉我这是否正确,或者我是否遗漏了任何主要概念或要点?我真的只是想了解为什么以及何时使用每个类 ICustomTypeDescriptor 在类中实现此接口完全覆盖类的本机属性,并用ICustomTypeDescriptor.GetProperties返回的Proper

我试图全面了解如何使用ICustomTypeDescriptor、TypeDescriptionProvider、TypeConverter和UITypeEditor来更改PropertyGrid的显示方式以及与对象的接口

有人能告诉我这是否正确,或者我是否遗漏了任何主要概念或要点?我真的只是想了解为什么以及何时使用每个类

ICustomTypeDescriptor

在类中实现此接口完全覆盖类的本机属性,并用ICustomTypeDescriptor.GetProperties返回的PropertyDescriptor替换它们 TypeDescriptionProvider

用于扩展类的现有属性 TypeDescriptionProvider通过TypeDescriptionProvider属性附加到类中 TypeDescriptionProvider的GetTypeDescriptor方法返回要附加到类型的现有属性的ICustomTypeDescriptor。 PropertyGrid将显示通过反射找到的类的属性,以及通过TypeDescriptionProvider添加到类中的属性 类型转换器

在类型之间转换 就使用PropertyGrid而言,PropertyGrid用于在复杂类型和可在特性网格中显示/编辑的基本类型之间进行转换。 TypeConverter的GetStandard values方法还可用于显示propertygrid中可能值的列表 UITypeEditor

定义用于操作复杂类型属性的自定义编辑器。 通过属性与属性关联。 因此,ICustomTypeDescriptor类型描述提供程序用于添加/更改/替换对象的整个属性。TypeConverter和UITypeEditor应用于单个属性,并控制这些特定属性的接口方式。

调整:

TypeDescriptionProvider

仍然替换元数据而不是扩展 也可以添加为TypeDescriptor.AddProvider 可以应用于每个类型以及每个实例,从而可以应用于列表,而无需实现ITypedList 类型转换器

对于PropertyGrid,这也是用于获取元数据的机制;请注意,ExpandableObjectConverter只是委托给TypeDescriptor.GetProperties,但情况并非总是如此 还负责重新创建不可变的对象,例如带有更改的结构 UITypeEditor

还负责在PropertyGrid中绘制预览框 其他:

IExtenderProvider-附加属性;这可能是您与TypeDescriptionProvider混淆的地方 ITypedList——大致上是ICustomTypeDescriptor的孪生子,但用于列表;可以通过在任何IList上使用TypeDescriptionProvider和非对象索引器来避免,即public T this[int index]{get;} IListSource—提供数据源和数据之间的间接寻址;例如,DataTable实现IListSource,在请求时返回DefaultView