4.0 中可以在 Properties.Settings 中存储通用字典吗?

发布于 2024-09-14 13:58:17 字数 163 浏览 2 评论 0原文

.net 4.0 中的新 Dictionary 是可序列化的,所以...我现在可以以某种方式在 Settings.SettingsSettings 中使用它吗?设计师.cs?

The new Dictionary<Tkey,TValue> in .net 4.0 is serializable, so... can I now somehow use this in the Settings.Settings or Settings.Designer.cs?

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

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

发布评论

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

评论(1

凉宸 2024-09-21 13:58:17

有点像。您可以定义一个继承自泛型类的非泛型类,然后在您的设置中引用它。例如:

namespace MyNamespace
{
    public class MyClassDictionary : System.Collections.Generic.Dictionary<string, MyClass>
    {}
}

当您为设置类型选择“浏览”时,您的命名空间可能不会出现在程序集/命名空间列表中,但您只需输入该类型的完全限定名称(例如,MyNamespace.MyClassDictionary) 进入对话框底部的文本框。定义自定义集合后,您需要编译一次。

Sort of. You can define a non-generic class that inherits from the generic class and then reference it in your settings. For example:

namespace MyNamespace
{
    public class MyClassDictionary : System.Collections.Generic.Dictionary<string, MyClass>
    {}
}

Your namespace may not appear in the list of assemblies/namespaces when you select "browse" for your setting's type, but you can just enter the fully qualified name of the type (e.g., MyNamespace.MyClassDictionary) into the text box at the bottom of the dialog. You will need to compile once after defining your custom collection.

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