NanoByte.Common  2.10.5
NanoByte.Common.Storage.JsonStorage Class Reference

Provides easy serialization to JSON files. More...

Static Public Member Functions

static T LoadJson< T > (Stream stream)
 Loads an object from an JSON file. More...
 
static T LoadJson< T > ([Localizable(false)] string path)
 Loads an object from an JSON file. More...
 
static T FromJsonString< T > ([Localizable(false)] string data)
 Loads an object from an JSON string. More...
 
static T FromJsonString< T > (string data, T anonymousType)
 Loads an object from an JSON string using an anonymous type as the target. More...
 
static void SaveJson< T > (this T data, Stream stream)
 Saves an object in an JSON stream. More...
 
static void SaveJson< T > (this T data, [Localizable(false)] string path)
 Saves an object in an JSON file. More...
 
static string ToJsonString< T > (this T data)
 Returns an object as an JSON string. More...
 
static T ReparseAsJson< T > (this object data)
 Reparses an object previously deserialized from JSON into a different representation. More...
 
static T ReparseAsJson< T > (this object data, T anonymousType)
 Reparses an object previously deserialized from JSON into a different representation using an anonymous type as the target. More...
 

Detailed Description

Provides easy serialization to JSON files.

Member Function Documentation

◆ FromJsonString< T >() [1/2]

static T NanoByte.Common.Storage.JsonStorage.FromJsonString< T > ( [Localizable(false)] string  data)
inlinestatic

Loads an object from an JSON string.

Template Parameters
TThe type of object the JSON string shall be converted into.
Parameters
dataThe JSON string to be parsed.
Returns
The loaded object.
Exceptions
InvalidDataExceptionA problem occurred while deserializing the JSON data.

◆ FromJsonString< T >() [2/2]

static T NanoByte.Common.Storage.JsonStorage.FromJsonString< T > ( string  data,
anonymousType 
)
static

Loads an object from an JSON string using an anonymous type as the target.

Template Parameters
TThe type of object the JSON string shall be converted into.
Parameters
dataThe JSON string to be parsed.
anonymousTypeAn instance of the anonymous type to parse to.
Returns
The deserialized object.

◆ LoadJson< T >() [1/2]

static T NanoByte.Common.Storage.JsonStorage.LoadJson< T > ( [Localizable(false)] string  path)
inlinestatic

Loads an object from an JSON file.

Template Parameters
TThe type of object the JSON stream shall be converted into.
Parameters
pathThe path of the file to load.
Returns
The loaded object.
Exceptions
IOExceptionA problem occurred while reading the file.
UnauthorizedAccessExceptionRead access to the file is not permitted.
InvalidDataExceptionA problem occurred while deserializing the JSON data.

Uses AtomicRead internally.

◆ LoadJson< T >() [2/2]

static T NanoByte.Common.Storage.JsonStorage.LoadJson< T > ( Stream  stream)
inlinestatic

Loads an object from an JSON file.

Template Parameters
TThe type of object the JSON stream shall be converted into.
Parameters
streamThe stream to read the encoded JSON data from.
Returns
The loaded object.
Exceptions
InvalidDataExceptionA problem occurred while deserializing the JSON data.

◆ ReparseAsJson< T >() [1/2]

static T NanoByte.Common.Storage.JsonStorage.ReparseAsJson< T > ( this object  data)
static

Reparses an object previously deserialized from JSON into a different representation.

Template Parameters
TThe type of object the data shall be converted into.
Parameters
dataThe object to be parsed again.
Returns
The deserialized object.

◆ ReparseAsJson< T >() [2/2]

static T NanoByte.Common.Storage.JsonStorage.ReparseAsJson< T > ( this object  data,
anonymousType 
)
static

Reparses an object previously deserialized from JSON into a different representation using an anonymous type as the target.

Template Parameters
TThe type of object the data shall be converted into.
Parameters
dataThe object to be parsed again.
anonymousTypeAn instance of the anonymous type to parse to.
Returns
The deserialized object.

◆ SaveJson< T >() [1/2]

static void NanoByte.Common.Storage.JsonStorage.SaveJson< T > ( this T  data,
[Localizable(false)] string  path 
)
inlinestatic

Saves an object in an JSON file.

This method performs an atomic write operation when possible.

Template Parameters
TThe type of object to be saved in an JSON stream.
Parameters
dataThe object to be stored.
pathThe path of the file to write.
Exceptions
IOExceptionA problem occurred while writing the file.
UnauthorizedAccessExceptionWrite access to the file is not permitted.

Uses AtomicWrite internally.

Type Constraints
T :notnull 

◆ SaveJson< T >() [2/2]

static void NanoByte.Common.Storage.JsonStorage.SaveJson< T > ( this T  data,
Stream  stream 
)
inlinestatic

Saves an object in an JSON stream.

Template Parameters
TThe type of object to be saved in an JSON stream.
Parameters
dataThe object to be stored.
streamThe stream to write the encoded JSON data to.

◆ ToJsonString< T >()

static string NanoByte.Common.Storage.JsonStorage.ToJsonString< T > ( this T  data)
inlinestatic

Returns an object as an JSON string.

Template Parameters
TThe type of object to be saved in an JSON string.
Parameters
dataThe object to be stored.
Returns
A string containing the JSON code.
Type Constraints
T :notnull 

The documentation for this class was generated from the following file: