使用Editor
屬性告訴至極類將被用於屬性編輯:
[Editor("Mynamespace.TypeSelector , System.Design", typeof(UITypeEditor)), Localizable(true)]
public Type PluginType { get; set; }
定義TypeSelector
類:
public class TypeSelector : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
return base.GetEditStyle(context);
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorService;
if (context == null || context.Instance == null || provider == null)
return value;
editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
FormTypeSelector dlg = new FormTypeSelector();
dlg.Value = value;
dlg.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
if (editorService.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
{
return dlg.Value;
}
return value;
}
}
唯一剩下的就是執行FormTypeSelector
您可以在其中選擇鍵入並將其分配給Value
屬性。在這裏,您可以使用反射來過濾實現IPlugin的程序集中的類型。
爲什麼downvote? –