Winform项目使用UitypeEditor自定义属性编辑器的差别,.Net Core无效,同样的项目修改为.Net Framework就有效,请问是什么原因?

Winform项目使用UitypeEditor自定义属性编辑器的差别,.Net Core无效,同样的项目修改为.Net Framework就有效,请问是什么原因?

问题描述:

有一个复杂的属性需要采用自定义的属性窗体来进行编辑,可是死活不生效,查遍了资料还是没有任何结果,MSDN上的代码拷贝过来也不生效,后来自己发现同样的代码Framework是有效的,本人用的是.Net Core 3.1,后来.Net 6.0也试过,依旧无效,不知道是API哪里变了,还是说Attribute的使用变了,望解惑。
这是MSDN上的链接:https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.design.uitypeeditor?view=netcore-3.1

以下是代码

  //
    internal class Editor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;  
        }


        public override bool IsDropDownResizable => false;

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService =(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            Form2 frm = new Form2();
            editorService.ShowDialog(frm);
            return "";
        }
    }
    
//
        [Editor(typeof(Editor), typeof(UITypeEditor))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public testabc test { get; set; } = new testabc();

测试确实存在这个问题,可能是MSDN文档有错误,请去https://developercommunity.visualstudio.com/report?space=61&entry=problem进行反馈。

添加System.Windows.Forms.dll 程序集。