2012-10-25 57 views
0

如何爲通用類型的所有實例指定自定義UI編輯器?該類型在另一個程序集中定義,我不擁有它。如何爲通用閉源類型的所有實例指定自定義UITypeEditor?


這是我嘗試過,通過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(); 
+1

只是DERIV e從你自己的類中選擇一個類,這樣你就可以給它自己的[Editor]屬性。 –

+1

不要以爲這是可能的。 TypeDescriptor解析機制基於類型的字典,並且沒有可以掛鉤的事件。 –

回答

0

嘗試一些在

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)); 
相關問題