我有一個Game application(WP8)
,我們在那裏保存多個attampts的分數,並顯示給用戶。獨立存儲 - 如何讀取附加數據
我有一個對象與字段noOfStonesPicked和noOfFruitsPicked。
這裏是我的代碼:
MyTopic topicObj = new MyTopic();
for (int i = 0; i <= 2; i++)
{
Test mt = new Test();
mt.noOfStonesPicked = 12;
mt.noOfFruitsPicked= 20;
topicObj.Stats.Add(mt);
}
WritetestTopicState(topicObj);
現在3次嘗試與每一個有noOfStonesPicked -12 and noOfFruitsPicked - 20
現在我已經保存此類似:
public static void WritetestTopicState(MyTopic topic)
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (StreamWriter sw = new StreamWriter(store.OpenFile("12.xml", FileMode.Append, FileAccess.Write)))
{
XmlSerializer serializer = new XmlSerializer(typeof(MyTopic));
serializer.Serialize(sw, topic);
serializer = null;
}
}
}
catch (Exception)
{
throw;
}
}
現在,我怎麼能retrive這些價值和顯示?
編輯
這是我曾嘗試:
public static MyTopic ReadMockTestTopicState()
{
MyTopic topic = null;
try
{
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
// Read application settings.
if (isoStore.FileExists("11.xml"))
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (StreamReader SR = new StreamReader(store.OpenFile("12.xml", FileMode.Open, FileAccess.Read)))
{
XmlSerializer serializer = new XmlSerializer(typeof(MyTopic));
topic = (MyTopic)serializer.Deserialize(SR);
serializer = null;
}
}
}
else
{
// If setting does not exists return default setting.
topic = new MyTopic();
}
}
}
catch (Exception)
{
throw;
}
return topic;
}
有什麼不對? – deeiip