Class Serializer
Common serialization tasks for SadConsole.
Inherited Members
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 |
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 |
| 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 |
| 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. |
TryLoad<T>(string, bool, out T?, JsonSerializerSettings?)
Tries to load the file, returning it as the specified tyupe.
Declaration
public static bool TryLoad<T>(string file, bool isCompressed, out T? obj, JsonSerializerSettings? settings = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | file | The file to load from. |
| bool | isCompressed | When true, indicates that the json |
| T | obj | The loaded object. |
| JsonSerializerSettings | settings | Optional settings to use during deserialization. If null, uses the Settings property. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T | The type of object to deserialize. |