把对象序列化成 xml文件,只能对简单实体类对象序列化哦
/// <summary>
/// XmlSerializationHelper Xml序列化工具
/// </summary>
public class XmlSerializationHelper
{
#region --- Functions Begin ---
/// <summary>
/// 从Xml文档读取获得对象
/// </summary>
/// <typeparam name="T">对象类</typeparam>
/// <param name="fileFullPath">xml文件完整路径</param>
/// <returns>对象实体,失败抛出异常</returns>
public static T LoadXmlFile<T>(string fileFullPath) where T : new()
{
FileStream fs = null;
try
{
fs = new FileStream(fileFullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
XmlSerializer xml = new XmlSerializer(typeof(T));
return (T)xml.Deserialize(fs);
}