如何为泛型类型的所有实例指定自定义UI编辑器?该类型是在另一个程序集中定义的,我不拥有该程序集。
这是我尝试过的,受到https://stackoverflow.com/a/849778/284795的启发,但没有任何效果(旧的编辑器仍然存在)。在这里,泛型类型是List<>和自定义编辑器DateTimeeditor -无稽之谈,但这只是一个示例,OK。
TypeDescriptor.AddAttributes(typeof(List<>),new EditorAttribute(typeof(System.ComponentModel.Design.DateTimeEditor),typeof(UITypeEditor)));
TypeDescriptor.GetEditor(new List<int>(),typeof(UITypeEditor)).Dump();发布于 2012-10-25 12:38:41
在…的行文中尝试一些东西
Customer是一个任意类
EditorBase被定义为
public class EditorBase : System.Drawing.Design.UITypeEditor {
}代码:
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));https://stackoverflow.com/questions/13065286
复制相似问题