229
+ − 1 using System;
+ − 2 using System.Collections.Generic;
+ − 3 using System.Linq;
+ − 4 using System.Text;
+ − 5 using System.Threading.Tasks;
+ − 6 using System.Xml;
+ − 7 using System.Xml.Linq;
+ − 8
+ − 9 namespace Implab.Xml {
+ − 10 public static class SerializationHelpers {
+ − 11 public static string SerializeAsString<T>(T obj) {
+ − 12 return SerializersPool<T>.Instance.SerializeAsString(obj);
+ − 13 }
+ − 14
+ − 15 public static void Serialize<T>(XmlWriter writer, T obj) {
+ − 16 SerializersPool<T>.Instance.Serialize(writer, obj);
+ − 17 }
+ − 18
+ − 19 public static XmlDocument SerializeAsXmlDocument<T>(T obj) {
+ − 20 var doc = new XmlDocument();
+ − 21 using (var writer = doc.CreateNavigator().AppendChild()) {
+ − 22 SerializersPool<T>.Instance.Serialize(writer, obj);
+ − 23 }
+ − 24 return doc;
+ − 25 }
+ − 26
+ − 27 public static XDocument SerializeAsXDocument<T>(T obj) {
+ − 28 var doc = new XDocument();
+ − 29 using (var writer = doc.CreateWriter()) {
+ − 30 SerializersPool<T>.Instance.Serialize(writer, obj);
+ − 31 }
+ − 32 return doc;
+ − 33 }
+ − 34
+ − 35 public static T DeserializeFromString<T>(string data) {
+ − 36 return SerializersPool<T>.Instance.DeserializeFromString(data);
+ − 37 }
+ − 38
+ − 39 public static T DeserializeFromXmlNode<T>(XmlNode node) {
+ − 40 Safe.ArgumentNotNull(node, nameof(node));
+ − 41 using (var reader = node.CreateNavigator().ReadSubtree())
+ − 42 return SerializersPool<T>.Instance.Deserialize(reader);
+ − 43 }
+ − 44 }
+ − 45 }