ICustomTypeDescriptor、TypeDescriptionProvider、TypeConverter 和 UITypeEditor
我试图全面了解如何使用 ICustomTypeDescriptor、TypeDescriptionProvider、TypeConverter 和 UITypeEditor 来更改 PropertyGrid 的显示方式以及与对象的交互方式。
有人可以告诉我这是否正确,或者我是否遗漏了任何主要概念或要点? 我真的只是想了解为什么以及何时使用每个类。
ICustomTypeDescriptor
- 在类中实现此接口完全覆盖类的本机属性,并将它们替换为 ICustomTypeDescriptor.GetProperties() 返回的 PropertyDescriptors
TypeDescriptionProvider
- 用于扩展现有属性类的
- TypeDescriptionProvider 通过 TypeDescriptionProvider 属性附加到类 TypeDescriptionProvider 的
- GetTypeDescriptor() 方法返回要附加到该类型的现有属性的 ICustomTypeDescriptor。
- PropertyGrid 将显示通过 Reflection 找到的类的属性,以及通过 TypeDescriptionProvider 添加到类的属性
TypeConverter
- 在类型之间进行转换
- 就使用 PropetyGrid 用于在复杂类型和基本类型之间进行转换而言可以在属性网格中显示/编辑。
- TypeConverter 的 GetStandard 值方法还可用于显示属性网格中的可能值列表
UITypeEditor
- 定义用于操作复杂类型属性的自定义编辑器。
- 通过属性与属性关联。
因此,ICustomTypeDescriptor 是一个 TypeDescription 提供程序,用于添加/更改/替换对象的整个属性。 TypeConverter 和 UITypeEditor 应用于各个属性并控制这些特定属性的交互方式。
I'm trying to get an overall understanding of how you use ICustomTypeDescriptor, TypeDescriptionProvider, TypeConverter, and UITypeEditor to change how a PropertyGrid displays and interfaces with an object.
Can someone tell me if this is right, or if I missed any major concepts or points? I'm really just trying to understand why and when you would use each class.
ICustomTypeDescriptor
- Implementing this interface in a class totaly overrides the native properties of a class and replaces them with the PropertyDescriptors returned by ICustomTypeDescriptor.GetProperties()
TypeDescriptionProvider
- Used to extend on the existing properties of a class
- A TypeDescriptionProvider is appended to a class through a TypeDescriptionProvider attribute
- The GetTypeDescriptor() method of the TypeDescriptionProvider returns an ICustomTypeDescriptor to be appended to the existing properties of the type.
- A PropertyGrid will show both the properties of the class found through Reflection, and the properties added to the class through the TypeDescriptionProvider
TypeConverter
- Converts between types
- In terms of using a PropetyGrid used to convert between complex types and primitive types that can be displayed/edited in the property grid.
- The GetStandard values method of a TypeConverter can also be used to show a list of possible values in the propertygrid
UITypeEditor
- Defines a custom editor for manipulating a property of a complex type.
- Associated with a property through an attribute.
So ICustomTypeDescriptor an TypeDescription provider are used to add/change/replace entire properties of objects. TypeConverter and UITypeEditor are applied to individual properties and control how those specific properties are interfaced with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调整:
TypeDescriptionProvider
TypeDescriptor.AddProvider
ITypedList
TypeConverter
PropertyGrid
来说,这也是用于获取元数据的机制; 请注意,ExpandableObjectConverter
只是委托给TypeDescriptor.GetProperties
,但情况并非总是如此<代码>UITypeEditor
PropertyGrid
中绘制预览框附加:
IExtenderProvider
- 附加属性; 这可能是您与TypeDescriptionProvider
ITypedList
混淆的地方ICustomTypeDescriptor
的双胞胎,但对于列表而言; 可以通过使用TypeDescriptionProvider
和任何IList
上的非对象索引器来避免,即public T this[int index] {get;}
IListSource
- 提供数据源和数据之间的间接连接; 例如,DataTable
实现IListSource
,在请求时返回DefaultView
Tweaks:
TypeDescriptionProvider
TypeDescriptor.AddProvider
ITypedList
TypeConverter
PropertyGrid
, this is also the mechanism used to obtain metadata; note thatExpandableObjectConverter
simply delegates toTypeDescriptor.GetProperties
, but this is not always the caseUITypeEditor
PropertyGrid
Additional:
IExtenderProvider
- appends properties; this may be what you were getting confused withTypeDescriptionProvider
ITypedList
- broadly the twin ofICustomTypeDescriptor
, but for lists; can be avoided by use ofTypeDescriptionProvider
and a non-object indexer on anyIList
, i.e.public T this[int index] {get;}
IListSource
- provides indirection between a data-source and the data; for example, aDataTable
implementsIListSource
, returningDefaultView
when requested