Auto status change to "Under Review"
@@ -1,45 +1,51 | |||
|
1 | 1 | using System; |
|
2 | 2 | using System.Collections.Generic; |
|
3 | using System.IO; | |
|
3 | 4 | using System.Linq; |
|
4 | 5 | using System.Text; |
|
5 | 6 | using System.Threading.Tasks; |
|
6 | 7 | using System.Xml; |
|
7 | 8 | using System.Xml.Linq; |
|
8 | 9 | |
|
9 | 10 | namespace Implab.Xml { |
|
10 | 11 | public static class SerializationHelpers { |
|
11 | 12 | public static string SerializeAsString<T>(T obj) { |
|
12 | 13 | return SerializersPool<T>.Instance.SerializeAsString(obj); |
|
13 | 14 | } |
|
14 | 15 | |
|
15 | 16 | public static void Serialize<T>(XmlWriter writer, T obj) { |
|
16 | 17 | SerializersPool<T>.Instance.Serialize(writer, obj); |
|
17 | 18 | } |
|
18 | 19 | |
|
19 | 20 | public static XmlDocument SerializeAsXmlDocument<T>(T obj) { |
|
20 | 21 | var doc = new XmlDocument(); |
|
21 | 22 | using (var writer = doc.CreateNavigator().AppendChild()) { |
|
22 | 23 | SerializersPool<T>.Instance.Serialize(writer, obj); |
|
23 | 24 | } |
|
24 | 25 | return doc; |
|
25 | 26 | } |
|
26 | 27 | |
|
27 | 28 | public static XDocument SerializeAsXDocument<T>(T obj) { |
|
28 | 29 | var doc = new XDocument(); |
|
29 | 30 | using (var writer = doc.CreateWriter()) { |
|
30 | 31 | SerializersPool<T>.Instance.Serialize(writer, obj); |
|
31 | 32 | } |
|
32 | 33 | return doc; |
|
33 | 34 | } |
|
34 | 35 | |
|
36 | public static void SerializeToFile<T>(string file, T obj) { | |
|
37 | using (var writer = File.CreateText(file)) | |
|
38 | SerializersPool<T>.Instance.Serialize(writer, obj); | |
|
39 | } | |
|
40 | ||
|
35 | 41 | public static T DeserializeFromString<T>(string data) { |
|
36 | 42 | return SerializersPool<T>.Instance.DeserializeFromString(data); |
|
37 | 43 | } |
|
38 | 44 | |
|
39 | 45 | public static T DeserializeFromXmlNode<T>(XmlNode node) { |
|
40 | 46 | Safe.ArgumentNotNull(node, nameof(node)); |
|
41 | 47 | using (var reader = node.CreateNavigator().ReadSubtree()) |
|
42 | 48 | return SerializersPool<T>.Instance.Deserialize(reader); |
|
43 | 49 | } |
|
44 | 50 | } |
|
45 | 51 | } |
General Comments 3
ok, latest stable version should be in default
You need to be logged in to leave comments.
Login now