-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSerializer.cs
49 lines (35 loc) · 1.36 KB
/
Serializer.cs
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
40
41
42
43
44
45
46
47
48
49
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace FirmarXades
{
public static class Serializer
{
public static XmlDocument SerializeToXmlDocument(object input, Type type, bool omitXmlDeclaration)
{
return SerializeToXmlDocument(input, type, omitXmlDeclaration, new XmlSerializerNamespaces());
}
public static XmlDocument SerializeToXmlDocument(object input, Type type, bool omitXmlDeclaration, XmlSerializerNamespaces ns)
{
XmlSerializer ser = new XmlSerializer(type);
XmlDocument xd = null;
using (MemoryStream memStm = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = omitXmlDeclaration;
XmlWriter writer = XmlWriter.Create(memStm, settings);
ser.Serialize(writer, input, ns);
memStm.Position = 0;
XmlReaderSettings readersettings = new XmlReaderSettings();
readersettings.IgnoreWhitespace = true;
using (var xtr = XmlReader.Create(memStm, readersettings))
{
xd = new XmlDocument();
xd.Load(xtr);
}
}
return xd;
}
}
}