1 反序列化函数定义
public object deSerialize(string filePath, Type type)
{
object t = null;
if (File.Exists(filePath))
{
using (StreamReader reader = new StreamReader(filePath))
{
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(type);
t = xmlSerializer.Deserialize(reader);
}
}
return t;
}
2 序列化函数定义
public void saveToXml(string filePath, object sourceObj, Type type, string rootName)
{
if (File.Exists(filePath) && sourceObj != null)
{
using (StreamWriter writer = new StreamWriter(filePath))
{
type = type != null ? type : sourceObj.GetType();
System.Xml.Serialization.XmlSerializer xmlSerializer = string.IsNullOrWhiteSpace(rootName) ?
new System.Xml.Serializ