Serializer Class
Definition
Section titled “Definition”Common serialization tasks for SadConsole.
public static class SerializerInheritance object
Properties
Section titled “Properties”Settings
Section titled “Settings”The settings to use during Save<T>(T, string, bool, JsonSerializerSettings) and Load<T>(string, bool, JsonSerializerSettings).
public static JsonSerializerSettings Settings { get; set; }Methods
Section titled “Methods”Serialize<T>(T)
Section titled “Serialize<T>(T)”A shortcut for serialization that uses SerializeObject(object, Type, JsonSerializerSettings) with the Settings property defined by this class.
public static string Serialize<T>(T instance)Parameters
Section titled “Parameters”instance T
The object to serialize.
Returns
Section titled “Returns”string
A json encoded string.
Deserialize<T>(string)
Section titled “Deserialize<T>(string)”A shortcut for serialization that uses DeserializeObject(string, Type, JsonSerializerSettings) with the Settings property defined by this class.
public static T Deserialize<T>(string json)Parameters
Section titled “Parameters”json string
The json string to create an object from.
Returns
Section titled “Returns”T
An object created from the json parameter.
Save<T>(T, string, bool, JsonSerializerSettings?)
Section titled “Save<T>(T, string, bool, JsonSerializerSettings?)”Serializes the instance to the specified file.
public static void Save<T>(T instance, string file, bool compress, JsonSerializerSettings? settings = null)Parameters
Section titled “Parameters”instance T
The object to serialize.
file string
The file to save the object to.
compress bool
When true, uses GZIP compression on the json string saved to the file
settings Newtonsoft.Json.JsonSerializerSettings
Optional settings to use during serialization. If null, uses the Settings property.
Load<T>(string, bool, JsonSerializerSettings?)
Section titled “Load<T>(string, bool, JsonSerializerSettings?)”Deserializes a new instance of T from the specified file.
public static T Load<T>(string file, bool isCompressed, JsonSerializerSettings? settings = null)Parameters
Section titled “Parameters”file string
The file to load from.
isCompressed bool
When true, indicates that the json file should be decompressed with GZIP compression.
settings Newtonsoft.Json.JsonSerializerSettings
Optional settings to use during deserialization. If null, uses the Settings property.
Returns
Section titled “Returns”T
A new object instance.
TryLoad<T>(string, bool, out T?, JsonSerializerSettings?)
Section titled “TryLoad<T>(string, bool, out T?, JsonSerializerSettings?)”Tries to load the file, returning it as the specified tyupe.
public static bool TryLoad<T>(string file, bool isCompressed, out T? obj, JsonSerializerSettings? settings = null)Parameters
Section titled “Parameters”file string
The file to load from.
isCompressed bool
When true, indicates that the json file should be decompressed with GZIP compression.
obj T
The loaded object.
settings Newtonsoft.Json.JsonSerializerSettings
Optional settings to use during deserialization. If null, uses the Settings property.