using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace ZRJ.Demo.Extend.Xml
{
public static class XmlHandle
{
public static T ConvertObject<T>(string path) where T : class
{
if (File.Exists(path))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (TextReader tr = new StreamReader(path))
{
return (T)serializer.Deserialize(tr);
}
}
return default(T);
}
public static void ConvertToXml<T>(string path, T source) where T : class
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (TextWriter tr = new StreamWriter(path))
{
xmlSerializer.Serialize(tr, source);
}
}
}
}