##// END OF EJS Templates
Added IObservable to TraceRegistry
Added IObservable to TraceRegistry

File last commit:

r278:6691aff01de1 v3
r288:90cef6117ced v3
Show More
SerializationHelpers.cs
93 lines | 3.3 KiB | text/x-csharp | CSharpLexer
/ Implab / Xml / SerializationHelpers.cs
cin
JsonXmlReader performance tuning...
r229 using System;
using System.Collections.Generic;
cin
Added SerializationHelpers.SerializeToFile method
r231 using System.IO;
cin
JsonXmlReader performance tuning...
r229 using System.Linq;
cin
Added XmlToJson xsl transformation....
r264 using System.Reflection;
cin
JsonXmlReader performance tuning...
r229 using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
cin
Added XmlToJson xsl transformation....
r264 using System.Xml.Serialization;
cin
JsonXmlReader performance tuning...
r229
namespace Implab.Xml {
public static class SerializationHelpers {
public static string SerializeAsString<T>(T obj) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 return XmlDefaultSerializer<T>.Instance.SerializeAsString(obj);
cin
JsonXmlReader performance tuning...
r229 }
public static void Serialize<T>(XmlWriter writer, T obj) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 XmlDefaultSerializer<T>.Instance.Serialize(writer, obj);
cin
JsonXmlReader performance tuning...
r229 }
public static XmlDocument SerializeAsXmlDocument<T>(T obj) {
var doc = new XmlDocument();
using (var writer = doc.CreateNavigator().AppendChild()) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 XmlDefaultSerializer<T>.Instance.Serialize(writer, obj);
cin
JsonXmlReader performance tuning...
r229 }
return doc;
}
public static XDocument SerializeAsXDocument<T>(T obj) {
var doc = new XDocument();
using (var writer = doc.CreateWriter()) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 XmlDefaultSerializer<T>.Instance.Serialize(writer, obj);
cin
JsonXmlReader performance tuning...
r229 }
return doc;
}
cin
Added SerializationHelpers.SerializeToFile method
r231 public static void SerializeToFile<T>(string file, T obj) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 XmlDefaultSerializer<T>.Instance.SerializeToFile(obj, file);
cin
Added SerializationHelpers.SerializeToFile method
r231 }
cin
Prerelease version of RunnableComponent...
r251 public static void SerializeToElementChild<T>(XmlElement element, T obj) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 XmlDefaultSerializer<T>.Instance.Serialize(obj, element);
cin
Prerelease version of RunnableComponent...
r251 }
public static T Deserialize<T>(XmlReader reader) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 return (T)XmlDefaultSerializer<T>.Instance.Deserialize(reader);
cin
Prerelease version of RunnableComponent...
r251 }
public static T DeserializeFromFile<T>(string file) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 return (T)XmlDefaultSerializer<T>.Instance.DeserializeFromFile(file);
cin
Prerelease version of RunnableComponent...
r251 }
cin
JsonXmlReader performance tuning...
r229 public static T DeserializeFromString<T>(string data) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 return (T)XmlDefaultSerializer<T>.Instance.DeserializeFromString(data);
cin
JsonXmlReader performance tuning...
r229 }
public static T DeserializeFromXmlNode<T>(XmlNode node) {
Safe.ArgumentNotNull(node, nameof(node));
using (var reader = node.CreateNavigator().ReadSubtree())
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 return (T)XmlDefaultSerializer<T>.Instance.Deserialize(reader);
cin
JsonXmlReader performance tuning...
r229 }
cin
Added XmlToJson xsl transformation....
r264
public static T DeserializeJson<T>(TextReader textReader) {
var options = new JsonXmlReaderOptions {
NamespaceUri = typeof(T).GetCustomAttribute<XmlRootAttribute>()?.Namespace,
RootName = typeof(T).Name,
FlattenArrays = true
};
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 using (var reader = JsonXmlReader.CreateJsonXmlReader(textReader, options))
cin
Added XmlToJson xsl transformation....
r264 return Deserialize<T>(reader);
}
public static T DeserializeJsonFromString<T>(string data) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 using (var reader = new StringReader(data)) {
cin
Added XmlToJson xsl transformation....
r264 return DeserializeJson<T>(reader);
}
}
public static void SerializeJson<T>(TextWriter writer, T obj) {
var doc = SerializeAsXmlDocument(obj);
XmlToJson.Default.Transform(doc, null, writer);
}
public static string SerializeJsonAsString<T>(T obj) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 using (var writer = new StringWriter()) {
cin
Added XmlToJson xsl transformation....
r264 SerializeJson(writer, obj);
return writer.ToString();
}
}
cin
JsonXmlReader performance tuning...
r229 }
}