views:

387

answers:

1

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?

A: 

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;
    }
SwDevMan81

related questions