为什么我无法从与设置文件相同的项目/程序集中为设置选择自定义类型?

发布于 2024-09-29 22:45:19 字数 337 浏览 1 评论 0原文

我试图将应用程序设置属性的类型设置为我在程序集中定义的自定义枚举类型(称为项目 A)。

在设置浏览器中,我单击“浏览”,然后出现“选择类型”对话框。

并且项目 A 中定义的类型似乎对我不可用。然而,类型可以从 A 引用的其他项目中获得。

对我来说,似乎无法理解人们将无法使用基础项目中定义的类型,所以我认为我做错了什么。我尝试过建造、清理、重建、重新启动,但没有任何运气,那么我到底错过了什么?

编辑:此处截图 http://tinypic.com/r/2ls8myb/7

I am trying to set the type of an application setting property to a custom enum type I have defined in my assembly (call this Project A)

In the settings browser I click browse and am presented with the "Select a Type" dialog box.

And the Types defined in Project A are not seem to be available to me. Yet types are available from other projects that A has referenced.

It seems almost beyond comprehension to me that one would not be able to use Types defined in the base project, so I assume I am doing something wrong. I have tried building, cleaning, rebuilding, restarting without any luck, so what exactly am I missing?

edit: screenshot here http://tinypic.com/r/2ls8myb/7

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恏ㄋ傷疤忘ㄋ疼 2024-10-06 22:45:19

我试图在 VS 2010 (.net 3.5) 中做同样的事情。事实证明,您可以使用设置设计器来完成此操作。如前所述,用户界面完全有缺陷,但如果您在浏览窗口中手动输入枚举的完全限定名称,它就会起作用。这样做的好处是不修改生成的代码 (*.Designer.cs),这总是最好避免的,因为当您这样做时,不能保证您的更改不会被覆盖。

PS - 这似乎只有在枚举是公共​​的情况下才有效。

设置 GUI:

在此处输入图像描述

然后手动键入完全限定的类型名称:

在此处输入图像描述

有一次我发誓我在“值”列中看到了枚举值的下拉菜单,但从那以后我就再也没有看到过它,而您只是看到了输入适当的值。

I was trying to do exactly the same thing in VS 2010 (.net 3.5). It turns out that you can do this using the Settings designer. The UI is totally flawed, as stated, but if you manually enter the fully qualified name of the enum in the Browse window it'll work. This has the benefit of not modifying generated code (*.Designer.cs), which is always good to avoid because when you do there's no guarantee that you're changes won't be overwritten.

PS - This only seems to work if the enum is public.

Settings GUI:

enter image description here

Then manually type fully-qualified type name:

enter image description here

At one point I swear I saw a drop-down of the enum values in the Value column, but I haven't seen it since and you just have to type an appropriate value in.

初心 2024-10-06 22:45:19

我也无法浏览到我的自定义类型。我可以通过在文本编辑器中打开 Settings.settings 文件并将设置添加到“设置”部分来添加自定义类型,如下所示:

<Setting Name="Options" Type="MyProject.MyOptions" Scope="User">
  <Value Profile="(Default)" />
</Setting>

设置设计器在我打开它时抱怨,但我只是对该对话框回答“否”,我可以在我的项目中使用自定义设置。

I could not browse to my custom type either. I was able to add my custom type by opening the Settings.settings file in a text editor and adding the setting to the Settings section like this:

<Setting Name="Options" Type="MyProject.MyOptions" Scope="User">
  <Value Profile="(Default)" />
</Setting>

The settings designer complains when I open it, but I just respond 'No' to that dialog, and I am able to use the custom setting in my project.

笛声青案梦长安 2024-10-06 22:45:19

因为你自己的类型是不可序列化的。使其可序列化,并且您可以在设置中定义它。

Because your own type is not serializable. Make it serializable and you can define it in your settings.

瑕疵 2024-10-06 22:45:19

我也在尝试同样的方法,解决方案非常简单:首先构建。

我添加了一个枚举类,定义了一些值,然后尝试用新的枚举替换 Settings.settings 文件中的 int 值,这样我以后就不必匹配该值了。未找到该类型。因为我还没有搭建。

构建后,一旦新的枚举类型已知并且可以使用:)

I was trying the same and the solution was very simple: Build first.

I added an enum class, defined some values and then tried to replace an int-value in the Settings.settings file with my new enum, so I don't have to match the value later. The type was not found. Because I did not build yet.

After Building once the new enum type is known and can be used :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文