using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace xml1
{
public class xmlHelper
{
/// <summary>
/// 序列化方法
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="path"></param>
public static void Ser<T>(T list,string path) where T:class
{
XmlSerializer xx = new XmlSerializer(typeof(T));
using (StreamWriter sw = File.CreateText(path))
{
xx.Serialize(sw, list);
}
}
public static T DeSer<T>(string path) where T:class
{
T list;//先定义一个空集合接收反序列化的数据
XmlSerializer le = new XmlSerializer(typeof(T));
using (StreamReader sr = File.OpenText(path))
{
list = le.Deserialize(sr) as T;//反序列化
}
return list;
}
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace xml1
{
public class xmlHelper
{
/// <summary>
/// 序列化方法
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="path"></param>
public static void Ser<T>(T list,string path) where T:class
{
XmlSerializer xx = new XmlSerializer(typeof(T));
using (StreamWriter sw = File.CreateText(path))
{
xx.Serialize(sw, list);
}
}
public static T DeSer<T>(string path) where T:class
{
T list;//先定义一个空集合接收反序列化的数据
XmlSerializer le = new XmlSerializer(typeof(T));
using (StreamReader sr = File.OpenText(path))
{
list = le.Deserialize(sr) as T;//反序列化
}
return list;
}
}
}