public static PropertyDescriptor CreateProperty(Type componentType, PropertyDescriptor oldPropertyDescriptor, params Attribute[] attributes)
{
// We must do some special case work here for extended properties. If the old property descriptor is really
// an extender property that is being surfaced on a component as a normal property, then we must
// do work here or else ReflectPropertyDescriptor will fail to resolve the get and set methods. We check
// for the necessary ExtenderProvidedPropertyAttribute and if we find it, we create an
// ExtendedPropertyDescriptor instead. We only do this if the component class is the same, since the user
// may want to re-route the property to a different target.
//
if (componentType == oldPropertyDescriptor.ComponentType)
{
ExtenderProvidedPropertyAttribute attr = (ExtenderProvidedPropertyAttribute)
oldPropertyDescriptor.Attributes[
typeof(ExtenderProvidedPropertyAttribute)];
ReflectPropertyDescriptor reflectDesc = attr.ExtenderProperty as ReflectPropertyDescriptor;
if (reflectDesc != null)
{
return new ExtendedPropertyDescriptor(oldPropertyDescriptor, attributes);
}
}
// This is either a normal prop or the caller has changed target classes.
//
return new ReflectPropertyDescriptor(componentType, oldPropertyDescriptor, attributes);
}