2using System.Runtime.Serialization;
18 return new XmlWriterSettings
33 var serializer =
new DataContractSerializer(typeof(T));
36 using (var stream =
new MemoryStream())
38 using (var writer = XmlWriter.Create(stream, settings))
40 serializer.WriteObject(writer, graph);
43 stream.Seek(0, SeekOrigin.Begin);
45 using (var reader =
new StreamReader(stream))
47 return reader.ReadToEnd();
59 var serializer =
new DataContractSerializer(typeof(T));
61 using (var stream = File.Create(path))
63 serializer.WriteObject(stream, graph);
73 var serializer =
new DataContractSerializer(typeof(T));
75 using (var stream = File.OpenRead(path))
77 return (T)serializer.ReadObject(stream);
87 var serializer =
new DataContractSerializer(typeof(T));
89 using (var stream =
new MemoryStream(bytes))
91 return (T)serializer.ReadObject(stream);
101 return LoadXml<T>(Encoding.UTF8.GetBytes(xml));
112 var serializer =
new DataContractSerializer(typeof(T));
114 using (var stream = File.Create(path))
116 Cryptography.EncryptToStream(stream, serializer, graph, key);
127 var serializer =
new DataContractSerializer(typeof(T));
129 using (var stream = File.OpenRead(path))
131 return Cryptography.DecryptFromStream<T>(stream, serializer, key);
Contains methods related to encryption and decryption.
Contains methods for serializing objects to and from XML.
static void SaveXml< T >(string path, T graph)
Saves the object to the file path using the DataContractSerializer.
static XmlWriterSettings PrettyXmlWriterSettings()
Returns a new instance of XML writer settings for pretty printing.
static T LoadXmlString< T >(string xml)
Loads an object from an XML string using the DataContractSerializer.
static void SaveEncryptedXml< T >(string path, T graph, byte[] key)
Serializes and encrypts and object to the specified file.
static string GetXmlString< T >(T graph, XmlWriterSettings settings=null)
Returns the pretty XML string for the object.
static T LoadEncryptedXml< T >(string path, byte[] key)
Decrypts and deserializes an object from the specified file.
static T LoadXml< T >(string path)
Loads an object from a file path using the DataContractSerializer.