Question

If I have a class that implements ICustomTypeDescriptor I can override the GetProperties() method to completely replace all the properties of the class with my custom PropertyDescriptors.

But what if i want to keep the existing properties of the class and append additional properties to the class? Is there a way to return a set of custom property descriptors that get added to the existing class properties?

For example I want the user to be able to define custom properties in my program that will show up in a property grid. The values of the custom properties will be stored in a Dictionary(string key, object value) collection, and I want to append PropertyDescriptors that will read and write values too and from this collection based on the key values.

I don't think IExtenderProvider would work because it only adds the properties of one class to another. But I need to be able to add and remove the properties dynamically at run time. Can I have an IExtenderProvider class that also implements ICustomTypeDescriptor so that properties it adds can be figured out at runtime?

Was it helpful?

Solution

Should be able to by just adding to the current collection:

    public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
    {
        PropertyDescriptorCollection cols = base.GetProperties(attributes);
        cols.Add(); // Add your custom property descriptor here
        return cols;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top