Xml Serialization Helper
using System;
using System.IO;
using System.Xml.Serialization;
namespace Objectware.Silverlight.Testing.Runner.Utilities
{
/// <summary>
/// Summary description for SerializationHelper.
/// </summary>
public static class SerializationHelper
{
private static string InternalSerializer(Type type, object content)
{
StringWriter writer = new StringWriter();
XmlSerializer serializer = new XmlSerializer(type);
serializer.Serialize(writer, content);
return writer.ToString();
}
public static string SerializeToString(Type type, object content)
{
return InternalSerializer(type, content);
}
public static string SerializeToString<T>(T content)
{
return InternalSerializer(typeof(T), content);
}
public static object DeserializeFromString(Type type, string content)
{
using (StringReader reader = new StringReader(content))
{
XmlSerializer serializer = new XmlSerializer(type);
return serializer.Deserialize(reader);
}
}
public static T DeserializeFromString<T>(string content)
{
using (StringReader reader = new StringReader(content))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(reader);
}
}
}
}
Related examples in the same category