2using System.Runtime.Serialization.Json;
19 var serializer =
new DataContractJsonSerializer(typeof(T));
22 using (var stream =
new MemoryStream())
24 using (var writer = JsonReaderWriterFactory.CreateJsonWriter(stream,
25 settings.Encoding,
false, settings.Indent, settings.IndentCharacters))
27 serializer.WriteObject(writer, graph);
30 stream.Seek(0, SeekOrigin.Begin);
32 using (var reader =
new StreamReader(stream))
34 return reader.ReadToEnd();
46 var serializer =
new DataContractJsonSerializer(typeof(T));
48 using (var stream = File.Create(path))
50 serializer.WriteObject(stream, graph);
60 var serializer =
new DataContractJsonSerializer(typeof(T));
62 using (var stream = File.OpenRead(path))
64 return (T)serializer.ReadObject(stream);
74 var serializer =
new DataContractJsonSerializer(typeof(T));
76 using (var stream =
new MemoryStream(bytes))
78 return (T)serializer.ReadObject(stream);
99 var serializer =
new DataContractJsonSerializer(typeof(T));
101 using (var stream = File.Create(path))
103 Cryptography.EncryptToStream(stream, serializer, graph, key);
114 var serializer =
new DataContractJsonSerializer(typeof(T));
116 using (var stream = File.OpenRead(path))
118 return Cryptography.DecryptFromStream<T>(stream, serializer, key);
Contains methods related to encryption and decryption.
Contains methods for serializing objects to and from JSON.
static void SaveJson< T >(string path, T graph)
Serializes the object as JSON to the specified file path.
static T LoadJsonString< T >(string json)
Loads a JSON object from a JSON string.
static string GetJsonString< T >(T graph, JsonWriterSettings settings=null)
Returns the JSON string for the object graph.
static T LoadJson< T >(string path)
Loads a JSON object from the specified path.
static void SaveEncryptedJson< T >(string path, T graph, byte[] key)
Serializes the object as encrypted JSON to the specified path.
static T LoadEncryptedJson< T >(string path, byte[] key)
Loads the object from an encrypted JSON file.
Contains settings for JSON writer formatting.
static JsonWriterSettings PrettyPrintSettings()
Returns new settings for pretty printing.