Show / Hide Table of Contents

Class Serializer

Common serialization tasks for SadConsole.

Inheritance
object
Serializer
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadConsole
Assembly: SadConsole.dll
Syntax
public static class Serializer

Properties

Settings

The settings to use during Save<T>(T, string, bool, JsonSerializerSettings?) and Load<T>(string, bool, JsonSerializerSettings?).

Declaration
public static JsonSerializerSettings Settings { get; set; }
Property Value
Type Description
JsonSerializerSettings

Methods

Deserialize<T>(string)

A shortcut for serialization that uses DeserializeObject(string, Type, JsonSerializerSettings) with the Settings property defined by this class.

Declaration
public static T Deserialize<T>(string json)
Parameters
Type Name Description
string json

The json string to create an object from.

Returns
Type Description
T

An object created from the json parameter.

Type Parameters
Name Description
T

Load<T>(string, bool, JsonSerializerSettings?)

Deserializes a new instance of T from the specified file.

Declaration
public static T Load<T>(string file, bool isCompressed, JsonSerializerSettings? settings = null)
Parameters
Type Name Description
string file

The file to load from.

bool isCompressed

When true, indicates that the json file should be decompressed with GZIP compression.

JsonSerializerSettings settings

Optional settings to use during deserialization. If null, uses the Settings property.

Returns
Type Description
T

A new object instance.

Type Parameters
Name Description
T

The type of object to deserialize.

Save<T>(T, string, bool, JsonSerializerSettings?)

Serializes the instance to the specified file.

Declaration
public static void Save<T>(T instance, string file, bool compress, JsonSerializerSettings? settings = null)
Parameters
Type Name Description
T instance

The object to serialize.

string file

The file to save the object to.

bool compress

When true, uses GZIP compression on the json string saved to the file

JsonSerializerSettings settings

Optional settings to use during serialization. If null, uses the Settings property.

Type Parameters
Name Description
T

Type of object to serialize

Serialize<T>(T)

A shortcut for serialization that uses SerializeObject(object, Type, JsonSerializerSettings) with the Settings property defined by this class.

Declaration
public static string Serialize<T>(T instance)
Parameters
Type Name Description
T instance

The object to serialize.

Returns
Type Description
string

A json encoded string.

Type Parameters
Name Description
T

The object type to serialize.

In this article

Back to top

Back to top Generated by DocFX