XML Serialization and Desiralization

Emil
Posted by Emil under C# category on | Points: 40 | Views : 956

public T DeSerializeForXml<T>(string filePath)
{

try
{
System.Xml.Serialization.XmlSerializer selializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
using (var reader = System.Xml.XmlReader.Create(filePath))
{
return (T)selializer.Deserialize(reader);
}
}
catch (Exception ex)
{
}
}

public void SerializeToXml<T>(string filePath, T obj)
{

try
{
System.Xml.Serialization.XmlSerializer selializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
using (var writer = System.Xml.XmlWriter.Create(filePath))
{
selializer.Serialize(writer, obj);
}
}
catch (Exception ex)
{

}
}

Comments or Responses

Login to post response