Table of Contents

Class JsonSettingsSerializer

Namespace
CarinaStudio.Configuration
Assembly
CarinaStudio.AppBase.Configuration.dll

Implementation of ISettingsSerializer which serialize settings to JSON format data.

public class JsonSettingsSerializer : ISettingsSerializer
Inheritance
JsonSettingsSerializer
Implements
Inherited Members
Extension Methods

Fields

BooleanType

Type name of bool.

protected const string BooleanType = "Boolean"

Field Value

string

ByteType

Type name of byte.

protected const string ByteType = "Byte"

Field Value

string

DateTimeType

Type name of DateTime.

protected const string DateTimeType = "DateTime"

Field Value

string

Default

Default instance.

public static readonly JsonSettingsSerializer Default

Field Value

JsonSettingsSerializer

DoubleType

Type name of double.

protected const string DoubleType = "Double"

Field Value

string

Int16Type

Type name of short.

protected const string Int16Type = "Int16"

Field Value

string

Int32Type

Type name of int.

protected const string Int32Type = "Int32"

Field Value

string

Int64Type

Type name of long.

protected const string Int64Type = "Int64"

Field Value

string

SingleType

Type name of float.

protected const string SingleType = "Single"

Field Value

string

StringType

Type name of string.

protected const string StringType = "String"

Field Value

string

Methods

Deserialize(Stream, out IDictionary<SettingKey, object>, out SettingsMetadata)

Deserialize keys and values of settings.

public void Deserialize(Stream stream, out IDictionary<SettingKey, object> values, out SettingsMetadata metadata)

Parameters

stream Stream

Stream to read serialized settings.

values IDictionary<SettingKey, object>

Deserialized keys and values.

metadata SettingsMetadata

Deserialized metadata.

GetTypeName(Type)

Get type name of given type of value.

protected virtual string GetTypeName(Type valueType)

Parameters

valueType Type

Type of value.

Returns

string

Type name.

ReadJsonValue(JsonElement, string)

Read setting value from JSON value according to type name. JSON value will be treated as string or string array if type name cannot be recognized.

protected object ReadJsonValue(JsonElement jsonValue, string typeName)

Parameters

jsonValue JsonElement

JSON value.

typeName string

Type name.

Returns

object

Read setting value.

ReadJsonValueAsString(JsonElement)

Read setting value from JSON value as string or string array.

protected object ReadJsonValueAsString(JsonElement jsonValue)

Parameters

jsonValue JsonElement

JSON value.

Returns

object

Setting value as string or string array.

Serialize(Stream, IDictionary<SettingKey, object>, SettingsMetadata)

Serialize settings.

public void Serialize(Stream stream, IDictionary<SettingKey, object> values, SettingsMetadata metadata)

Parameters

stream Stream

Stream to write serialized settings.

values IDictionary<SettingKey, object>

All keys and values.

metadata SettingsMetadata

Metadata.

WriteJsonValue(Utf8JsonWriter, string, object)

Write JSON value according to type name.

protected virtual void WriteJsonValue(Utf8JsonWriter writer, string typeName, object value)

Parameters

writer Utf8JsonWriter

Utf8JsonWriter.

typeName string

Type name.

value object

Value to write.