-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlSerializer.cs
More file actions
39 lines (34 loc) · 1.13 KB
/
XmlSerializer.cs
File metadata and controls
39 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Pin.Model;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Pin
{
public class XmlSerializer
{
internal string Serialize()
{
StringBuilder xmlOutput = new StringBuilder();
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(GetType());
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = false;
settings.NewLineHandling = NewLineHandling.None;
using (XmlWriter writer = XmlWriter.Create(xmlOutput, settings))
{
xmlSerializer.Serialize(writer, this);
return xmlOutput.ToString();
}
}
internal static T Deserialize<T> (string objectData)
{
var serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
object result;
using (TextReader reader = new StringReader(objectData))
{
result = serializer.Deserialize(reader);
}
return (T)result;
}
}
}