【发布时间】:2012-10-25 09:12:59
【问题描述】:
如何为 generic 类型的所有实例指定自定义 UI 编辑器?该类型是在另一个我不拥有的程序集中定义的。
这是我尝试过的,受https://stackoverflow.com/a/849778/284795 启发,但没有任何效果(旧编辑器仍然存在)。在这里,泛型类型是List<> 和自定义编辑器DateTimeeditor - 废话,但这只是一个示例。
TypeDescriptor.AddAttributes(typeof(List<>),new EditorAttribute(typeof(System.ComponentModel.Design.DateTimeEditor),typeof(UITypeEditor)));
TypeDescriptor.GetEditor(new List<int>(),typeof(UITypeEditor)).Dump();
【问题讨论】:
-
只需从该类型派生您自己的类,这样您就可以给它自己的 [Editor] 属性。
-
不要认为这是可能的。 TypeDescriptor 解析机制基于类型字典,没有可以挂钩的事件。
标签: c# .net typedescriptor uitypeeditor