1
#if !SILVERLIGHT && !MONOTOUCH && !XBOX
6
using System.Runtime.Serialization;
7
using ServiceStack.DesignPatterns.Serialization;
9
namespace ServiceStack.ServiceModel.Serialization
11
public class XmlSerializableDeserializer : IStringDeserializer
13
public static XmlSerializableDeserializer Instance = new XmlSerializableDeserializer();
15
public To Parse<To>(string xml)
17
var type = typeof(To);
18
return (To)Parse(xml, type);
21
public object Parse(string xml, Type type)
25
var bytes = Encoding.UTF8.GetBytes(xml);
26
using (var reader = XmlDictionaryReader.CreateTextReader(bytes, new XmlDictionaryReaderQuotas()))
28
var serializer = new System.Xml.Serialization.XmlSerializer(type);
29
return serializer.Deserialize(reader);
34
throw new SerializationException(string.Format("Error serializing object of type {0}", type.FullName), ex);
38
public To Parse<To>(TextReader from)
40
var type = typeof(To);
45
var serializer = new System.Xml.Serialization.XmlSerializer(type);
46
return (To)serializer.Deserialize(from);
51
throw new SerializationException(string.Format("Error serializing object of type {0}", type.FullName), ex);
55
public To Parse<To>(Stream from)
57
var type = typeof(To);
60
using (var reader = XmlDictionaryReader.CreateTextReader(from, new XmlDictionaryReaderQuotas()))
62
var serializer = new System.Xml.Serialization.XmlSerializer(type);
63
return (To)serializer.Deserialize(reader);
68
throw new SerializationException(string.Format("Error serializing object of type {0}", type.FullName), ex);