C#: Insert custom TypeConverter on a property at runtime, from inside a custom UITypeEditor
Posted
by Pedery
on Stack Overflow
See other posts from Stack Overflow
or by Pedery
Published on 2010-03-29T03:26:04Z
Indexed on
2010/03/29
3:33 UTC
Read the original article
Hit count: 611
I've created a custom UITypeEditor.
Can I possibly insert an attribute that also attaches a TypeConverter to my property from inside the UITypeEditor class?
I've tried the following, but nothing happens, no matter how I twist and turn it:
Attribute[] newAttributes = new Attribute[1];
newAttributes[0] = new TypeConverterAttribute(typeof(BooleanConverter));
Now, the above needs to have the following attached to it somehow:
TypeDescriptor.AddAttributes(context.Instance.PROPERTYNAME, newAttributes);
...but first of all I don't know how to get to the property in question in a generic way, and all code I try just fails. Even if I try to assign the TypeConverter in this manner globally, it fails. (Setting it as an attribute on the property itself works though, just to rule out that the bug is in that part.)
© Stack Overflow or respective owner