StringDictionary不保存为用户设置 [英] StringDictionary not saving as user setting

查看:141
本文介绍了StringDictionary不保存为用户设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用户范围类型为System.Collections.Specialized.StringDictionary设置。每当我打开本地设置,我可以看到它在配置,但它是空的。

I've created a user scoped setting with the type "System.Collections.Specialized.StringDictionary". Whenever I open the local settings, I can see it in the config, but it's empty.

我有其他的用户设置保存正确的,但是这本字典似乎并没有被拯救的。

I have other user settings that save correctly, but this dictionary doesn't seem to be saving at all.

有什么我需要做的,为了得到一本字典拯救?

Is there something I need to do in order to get a dictionary to save?

推荐答案

如果你从code设置它,你记住调用 Settings.Save()

If you're setting it from code, are you remembering to call Settings.Save()?

编辑:男孩我是哑巴,我只记得我有同样的问题,我和辛劳了好几个小时。问题是,词典不序列化到XML(即使它确实应该)。你有两个选择。您可以指定自己的序列化方法的字典,或者你可以欺骗。

Boy am I dumb, I just remembered I had the same problem myself and labored over it for hours. The problem is that the Dictionary doesn't serialize to XML (even though it really should). You have two options. You can specify your own serialization methods for the dictionary, or you can cheat.

如果你不关心能够读取/在XML编辑值,你可以添加一个 [SettingSerializeAs(SettingsSerializeAs.Binary)] 属性的环境。能够完成任务,但它的快速和肮脏的方法。

If you don't care about being able to read/edit the values in the XML, you can add a [SettingSerializeAs(SettingsSerializeAs.Binary)] attribute to the setting. Gets the job done, but it's the quick-and-dirty approach.

这篇关于StringDictionary不保存为用户设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆