using System.IO;
namespace MediaBrowser.Common.Serialization
{
///
/// Provides a wrapper around third party xml serialization.
///
public class XmlSerializer
{
public static void SerializeToStream(T obj, Stream stream)
{
GetSerializer().Serialize(stream, obj);
}
public static void SerializeToFile(T obj, string file)
{
using (FileStream stream = new FileStream(file, FileMode.Create))
{
GetSerializer().Serialize(stream, obj);
}
}
public static T DeserializeFromFile(string file)
{
using (Stream stream = File.OpenRead(file))
{
return (T)GetSerializer().Deserialize(stream);
}
}
public static T DeserializeFromStream(Stream stream)
{
return (T)GetSerializer().Deserialize(stream);
}
private static System.Xml.Serialization.XmlSerializer GetSerializer()
{
return new System.Xml.Serialization.XmlSerializer(typeof(T));
}
}
}