什么是[Editor(typeof(FolderNameEditor),typeof(UITypeEditor)]的C+

What is C++/CLI version of [Editor(typeof(FolderNameEditor), typeof(UITypeEditor))]?

本文关键字:typeof UITypeEditor FolderNameEditor Editor 什么      更新时间:2023-10-16

这是一个令人尴尬的问题,但我觉得在过去的几个小时里我什么都试过了。

我只想添加以下属性到我的属性

#using <System.Drawing.dll>
#using <System.Design.dll>
...
using namespace System::Drawing::Design;
using namespace System::Configuration;
using namespace System::ComponentModel;
using namespace System::Windows::Forms::Design;
...
[Editor(typeof(FolderNameEditor), typeof(UITypeEditor))]
property System::String^           DefaultWorkingDirectory;

首先,我按原样进行了尝试,编译器说"非法使用类型(FolderNameEditor)

现在我尝试了这个

[Editor(Type::GetType("System.Windows.Form.Design.FolderNameEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), 
Type::GetType("System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"))]

但它说非法属性论点。

如果我执行以下操作,C++/CLI项目将编译

[Editor("System.Windows.Form.Design.FolderNameEditor", "System.Drawing.Design.UITypeEditor")]

但每当我试图从C#项目中获取该项目的引用时,我都会收到一个错误,说命名空间丢失了。如果我注释掉上面的编辑器属性和#using和using namespace,一切都很好。

由于某些原因,我在MSDN中找不到相关材料,如果您能指出合适的文档,我将不胜感激。

更新:C#项目是.NET 4客户端配置文件,这就是我收到错误指示缺少命名空间的原因,这是误导性的。将目标框架更改为.NET 4解决了问题。

相当于typeof()的C++/CLI是::typeid。试试这个:

[Editor(FolderNameEditor::typeid, UITypeEditor::typeid)]