我试过搜索谷歌并在这里找不到任何好的东西。任何帮助,将不胜感激。
无论我在哪里尝试将自己的对象添加到用户设置,该应用都会失败。 Game类非常简单,有一些string和int属性。如果相关我可以用完整的细节更新帖子。
每当我设置CurrentGame1的值时,它都会在save方法中出现,并显示错误“不支持多维数组”。我需要序列化对象吗?如果我可以避免它,我宁愿没有并发症
private Game CurrentGame1
{
get
{
if (IsolatedStorageSettings.ApplicationSettings.SingleOrDefault(z => z.Key == "Game1").Key == null) {
IsolatedStorageSettings.ApplicationSettings.Add("Game1", new Game());
IsolatedStorageSettings.ApplicationSettings.Save();
}
return IsolatedStorageSettings.ApplicationSettings["Game1"] as Game;
}
set
{
IsolatedStorageSettings.ApplicationSettings.Remove("Game1");
IsolatedStorageSettings.ApplicationSettings.Add("Game1", value);
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
答案 0 :(得分:2)
将多维数组(foo [x,y])切换为数组数组(foo [x] [y])。
答案 1 :(得分:1)
您传递给的任何对象都必须支持序列化(和反序列化)我猜你定义Game
的方式是你没有启用它。
但是我建议自己序列化(和反序列化)对象,尽管IsolatdStorage在内部使用DataContractSerializer
,这非常慢。
如果您可以自己更快地序列化对象,然后将一个简单类型传递给IsolatedStorageSettings,那么您应该能够获得更好的性能。