~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/ServiceStack/src/ServiceStack.Common/ServiceModel/Serialization/XmlSerializableSerializer.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !SILVERLIGHT && !MONOTOUCH && !XBOX
 
2
using System;
 
3
using System.IO;
 
4
using System.Runtime.Serialization;
 
5
using System.Text;
 
6
using System.Xml;
 
7
using ServiceStack.DesignPatterns.Serialization;
 
8
using ServiceStack.ServiceModel.Support;
 
9
 
 
10
namespace ServiceStack.ServiceModel.Serialization
 
11
{
 
12
    public class XmlSerializableSerializer : IStringSerializer 
 
13
    {
 
14
        public static XmlSerializableSerializer Instance = new XmlSerializableSerializer();
 
15
 
 
16
        public string Parse<XmlDto>(XmlDto from)
 
17
        {
 
18
            try
 
19
            {
 
20
                using (var ms = new MemoryStream())
 
21
                {
 
22
                    using (XmlWriter xw = new XmlTextWriter(ms, Encoding.UTF8))
 
23
                    {
 
24
                        var ser = new XmlSerializerWrapper(from.GetType());
 
25
                        ser.WriteObject(xw, from);
 
26
                        xw.Flush();
 
27
                        ms.Seek(0, SeekOrigin.Begin);
 
28
                        using (var reader = new StreamReader(ms))
 
29
                        {
 
30
                            return reader.ReadToEnd();
 
31
                        }
 
32
                    }
 
33
                }
 
34
            }
 
35
            catch (Exception ex)
 
36
            {
 
37
                throw new SerializationException(string.Format("Error serializing object of type {0}", from.GetType().FullName), ex);
 
38
            }
 
39
        }
 
40
    }
 
41
}
 
42
#endif
 
 
b'\\ No newline at end of file'