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.
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