I have inherited the PropertyDescriptor
class to provide kind of 'dynamic' properties. I'm adding some attributes to the PropertyDescriptor. This works perfectly.
When displaying a object in a PropertyGrid
, the ReadOnlyAttribute
works, but the EditorAttribute
doesn't work!
internal class ParameterDescriptor: PropertyDescriptor {
//...
public ParameterDescriptor(/* ... */) {
List<Attribute> a = new List<Attribute>();
string editor = "System.ComponentModel.Design.MultilineStringEditor,System.Design";
//...
a.Add(new ReadOnlyAttribute(true)); // works
a.Add(new DescriptionAttribute("text")); // works
a.Add(new EditorAttribute(editor, typeof(UITypeEditor))); // doesn't work!
//...
this.AttributeArray = a.ToArray();
}
}
The object that is displayed uses a inherited TypeConverter
:
public class ParameterBoxTypeConverter: TypeConverter {
public override bool GetPropertiesSupported(ITypeDescriptorContext context) {
return true;
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) {
List<PropertyDescriptor> desc = new List<PropertyDescriptor>();
//...
ParameterDescriptor d = new ParameterDescriptor(/* ... */);
desc.Add(d);
//....
return new PropertyDescriptorCollection(desc.ToArray());
}
I'm stuck, because the PropertyGrid
simply isn't showing anything (I expected a "..." at the property value). And it seems there's no way to debug!
So how can I find what's wrong here?
Is there a way to debug into the PropertyGrid, etc?
From a few quick tests, the name needs to be fuly qualified:
const string name = "System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
attribs.Add(new EditorAttribute(name, typeof(UITypeEditor)));
Internally, it uses Type.GetType
, and:
var type1 = Type.GetType("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
// ^^^ not null
var type2 = Type.GetType("System.ComponentModel.Design.MultilineStringEditor, System.Design");
// ^^^ null
Of course, you could just use:
attribs.Add(new EditorAttribute(typeof(MultilineStringEditor), typeof(UITypeEditor)));
Alternatively, you can override GetEditor
and do whatever your want.