How to specify a custom UITypeEditor for all instances of a generic closed-source type?

1.3k views Asked by At

How can I specify a custom UI editor for all instances of a generic type? The type is defined in another assembly, which I don't own.


This is what I tried, inspired by https://stackoverflow.com/a/849778/284795 but it didn't have any effect (the old editor remains). Here, the generic type is List<> and the custom editor DateTimeeditor - nonsense but this is just an example OK.

TypeDescriptor.AddAttributes(typeof(List<>),new EditorAttribute(typeof(System.ComponentModel.Design.DateTimeEditor),typeof(UITypeEditor)));
TypeDescriptor.GetEditor(new List<int>(),typeof(UITypeEditor)).Dump();
1

There are 1 answers

0
MaLio On

Try something in the lines of

Customer is an arbitrary class

EditorBase is defined as

public class EditorBase : System.Drawing.Design.UITypeEditor {
}

Code:

System.Collections.Hashtable table = new System.Collections.Hashtable();

table.Add(typeof(Customer), typeof(EditorBase).AssemblyQualifiedName);

System.ComponentModel.TypeDescriptor.AddEditorTable(typeof(System.Drawing.Design.UITypeEditor), table);

object editor = System.ComponentModel.TypeDescriptor.GetEditor(typeof(Customer), typeof(System.Drawing.Design.UITypeEditor));