A generic Xml Serializer De-Serializer code snap
public class SerializeDeserialize
{
public static void SerializeData<T>(string filePath, T data)
{
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.CreateNew))
{
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(data.GetType());
x.Serialize(fs, data);
}
}public static T DeSerializeData<T>(string filePath)
{
T data;
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(T));
object obj = x.Deserialize(fs);
data = (T)obj;
}return data;
}
}
No comments:
Post a Comment