【发布时间】:2013-12-06 00:11:55
【问题描述】:
我创建了一些自定义设置类型:
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
public class PathSetting
{
public PathSetting(string path = "", bool enabled = true)
{
Path = path;
Enabled = enabled;
}
public string Path {get; set;}
public bool Enabled { get; set; }
}
和
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
public class PathUserSettings : ApplicationSettingsBase
{
private List<PathSetting> paths;
public List<PathSetting> Paths
{
get { return paths; }
set { paths = value; }
}
}
然后在我的 Settings.setting 文件中,我创建了一个名为 paths of type (Browse > myNamespace.PathUserSettings) 的项目。我没有将其设置为任何内容,然后在我的主要表单加载中输入了以下代码:
if (Properties.Settings.Default.paths == null)
{
Properties.Settings.Default.paths.Paths.Add(new PathSetting("prefs/*.pref"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("levels/*.mis"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("User Data/"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("core/prefs.cs"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("scripts/client/prefs.cs"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("scripts/server/prefs.cs"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("scripts/client/config.cs"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("xml/Swarms.xml"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("xml/OldSwarms.xml"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("art/props/*"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("art/swarm/*"));
Properties.Settings.Default.paths.Paths.Add(new PathSetting("art/datablocks/convertedDatablocks.cs"));
Properties.Settings.Default.Save();
}
但由于某种原因,它没有通过第一个 Add 调用。我什至不能真正介入。你不能添加到列表中吗?我不完全了解设置系统的工作原理,而且这样的例子似乎并不多。
感谢任何帮助!
【问题讨论】:
-
指示是否抛出任何异常以及是否还显示堆栈跟踪通常很有帮助。就目前而言,尚不清楚“没有通过第一个 Add 调用”是什么意思。
标签: c# winforms application-settings