views:

718

answers:

1

I have a base class with a number of properties. Included in this is a list of extended properties with metadata. This is a List of a custom class containing DisplayName, Description, Name, Type & Value properties to help the PropertyGrid along.

The desired end result would be the PropertyGrid showing my base class properties merged with my extended properties from the list above. I dont want the PropertyGrid to show my list as a single entry, but to merge each of the extended properties with my base class properties. Essentially the PropertyGrid believes my list of extended properties are first class properties of the object.

Is this possible using Reflection or dynamic type descriptors?

+1  A: 

It should be rather simple with custom TypeConverter.

Something like this would be a start:

public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
  return true;
}

public override PropertyDescriptorCollection GetProperties(
    ITypeDescriptorContext context, object value, Attribute[] attributes)
{
  return base.GetProperties(context, value, attributes).
    Concat(TypeDescriptor.GetConverter(typeof(TheBaseType)).
    GetProperties(context, value, attributes));
}
leppie
Thanks leppie, could you put this into context please. i.e. is this a custom type converter for my ExtendedProperty class or my Base class?Also Concat does not come up in intellisense for PropertyDescriptorCollection (targetted framework = 3.5)
dbez
This will be a type converter that you apply to the derived class. 'Concat' is a pseudo function, you will have yo write it :)
leppie