
we have a class X with some properties that is added to the PropertyGrid.SelectedObject. the functionality (and properties) of class X are extended by using the decorator pattern like this:
class X : OurPropertyGridObject
{
List<Decorator> decorators { get; }
}
class Decorator : OurPropertyGridObject
{
string SomeProperty { get; set; }
}
class DecoratorA : Decorator
{ }
class DecoratorB : Decorator
{ }
we use a custom TypeDecriptorFactory to produce the properties for the property grid. it gets all the properties of a OurPropertyGridObject, including that of all decorators, and adds them to the properties like this:
protected override IList<IPropertyDataAccessor> GetProperties(object value, DataFactoryOptions options)
{
List<IPropertyDataAccessor> result = new List<IPropertyDataAccessor>();
...
result.Add(new PropertyDescriptorDataAccessor(ourPropertyGridObjectRef, propertyName));
...
return result;
}
this works, but what we see now is that "SomeProperty" appears in the property grid once for each decorator. we would have liked to have it in the property grid just once, merged for all of those decorators. what we did now is move all properties from the Decorator class to a separate DecoratorY but that creates unwanted dependencies between decorators. is it possible to merge the property on the Decorator class for all deriving classes? how?
[Modified 13 years ago]