简体   繁体   English

使用ListDictionary类设置(Settings.settings)

[英]Using a ListDictionary Class setting (Settings.settings)

In my C# program (.net v4, MS Visual C# Express) I am attempting to use a setting of the class ListDictionary. 在我的C#程序(.net v4,MS Visual C#Express)中,我尝试使用ListDictionary类的设置。

Here's my test code: 这是我的测试代码:

// String setting
Properties.Settings.Default.StringTest = "Llama llama LLAMA!";

// ListDictionary setting
ListDictionary ld = new ListDictionary();
ld.Add("key1", "llama");
ld.Add("key2", "alpaca");

Properties.Settings.Default.LDTest = ld;

// Save settings
Properties.Settings.Default.Save();

After executing my code, the user.config file is written with the string setting, but not with the ListDictionary setting (excerpt): 执行我的代码后,将使用字符串设置而不是ListDictionary设置(摘录)写入user.config文件:

    <setting name="StringTest" serializeAs="String">
        <value>Llama llama LLAMA!</value>
    </setting>
    <setting name="LDTest" serializeAs="Xml">
        <value />
    </setting>

List Dictionary is listed as being serializable here , but is there some manual work I need to do to get it into a setting file? 列表字典在此处被列为可序列化的,但是我需要做一些手动工作才能将其放入设置文件中? Furthermore, is there any way to figure out what classes/types are able to be used as settings and which are not? 此外,有什么方法可以确定哪些类/类型可以用作设置,哪些不可以用作设置?

Make sure you have Break When Exceptions thrown enabled, as well as .Net Framework Source Stepping if you want see this exception. 如果您希望看到此异常,请确保已启用“引发异常时中断”,以及.Net Framework Source Steping。 While I don't think you want to serialize complex datatypes to the Settings.settings file, you could serialize this to a string separated by semicolons and commas if you were really dead set on doing this. 虽然我不希望将复杂的数据类型序列化为Settings.settings文件,但是如果您确实不愿意这样做,则可以将其序列化为由分号和逗号分隔的字符串。

确保启用了“异常时休息”功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM