TXT

XmlSerializeHelper

By Howard Ford,2014-09-20 16:10
18 views 0
XmlSerializeHelper

ï??using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.IO;

    using System.Xml.Serialization;

namespace BPlan.Common

    {

     /// <summary>

     /// åº?列化XMLå??åŠ?ç??

     /// </summary>

     public class XmlSerializeHelper

     {

     /// <summary>

     /// å??åº?列化

     /// </summary>

     /// <typeparam name="T">å??è??</typeparam>

     /// <param name="path">XMLè??å?„</param>

     /// <returns></returns>

     public static T Deserialize<T>(string path) where T : class

     {

     using (StreamReader sr = new StreamReader(path))

     {

     XmlSerializer s = new XmlSerializer(typeof(T));

     object o = s.Deserialize(sr);

     return o as T;

     }

     }

     /// <summary>

     /// åº?列化

     /// </summary>

     /// <typeparam name="T">å??è??</typeparam>

     /// <param name="path">XMLä??å??è??å?„</param>

     /// <param name="t">å??è??å?žä?‹</param>

     public static void Serialize<T>(string path, T t)

     {

     using (StreamWriter sw = new StreamWriter(path))

     {

     XmlSerializer s = new XmlSerializer(typeof(T));

     s.Serialize(sw, t);

     }

     }

     }

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com