序列化
private void SerializeMethd<T>(T obj,string path)
{
try
{
File.Delete(path);
XmlSerializer xs = new XmlSerializer(typeof(T));
using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
{
xs.Serialize(stream, obj);
}
}
catch (Exception ex)
{
}
}
反序列化
private T DeSerializeMethd<T>(string path)
{
try
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
T obj = (T)xs.Deserialize(stream);
return obj;
}
}
catch (Exception ex)
{
throw;
}
}