在WP7开发中,在IsolatedStorage中存储Stack类型对象的最简单方法是什么?
答案 0 :(得分:0)
您可以将其序列化为一个独立的文件,即:
public static class IsolatedSerializer
{
public static void Save<T>(string filename, T t)
{
XmlSerializer xmlSerializer = new XmlSerializer(t.GetType());
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = store.CreateFile(filename))
{
xmlSerializer.Serialize(stream, t);
}
}
public static T Load<T>(string filename)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = store.CreateFile(filename))
{
return (T)xmlSerializer.Deserialize(stream);
}
}
}
或者由于某些原因这不适用于WP7?
event
- 这非常棘手,并且不适用于xml序列化程序。