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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…