XmlSerializer序列化一组成员到文本文件
写入:
using (System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
{
using (System.IO.IsolatedStorage.IsolatedStorageFileStream fs = isf.CreateFile(fileName))
{
System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(List<TripInfo>));
ser.Serialize(fs, Trips);
}
}
读取:
List<TripInfo> trips = null;
System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(List<TripInfo>));
object obj = ser.Deserialize(fs);
if (null != obj && obj is List<TripInfo>)
{
trips = obj as List<TripInfo>;
}
else
{
trips = new List<TripInfo>();
}