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>();
            }

posted on 2012-08-02 17:44  冰危节奏  阅读(328)  评论(0编辑  收藏  举报

导航