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
ByteType
Type name of byte.
protected const string ByteType = "Byte"
Field Value
DateTimeType
Type name of DateTime.
protected const string DateTimeType = "DateTime"
Field Value
Default
Default instance.
public static readonly JsonSettingsSerializer Default
Field Value
DoubleType
Type name of double.
protected const string DoubleType = "Double"
Field Value
Int16Type
Type name of short.
protected const string Int16Type = "Int16"
Field Value
Int32Type
Type name of int.
protected const string Int32Type = "Int32"
Field Value
Int64Type
Type name of long.
protected const string Int64Type = "Int64"
Field Value
SingleType
Type name of float.
protected const string SingleType = "Single"
Field Value
StringType
Type name of string.
protected const string StringType = "String"
Field Value
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
streamStreamStream to read serialized settings.
valuesIDictionary<SettingKey, object>Deserialized keys and values.
metadataSettingsMetadataDeserialized metadata.
GetTypeName(Type)
Get type name of given type of value.
protected virtual string GetTypeName(Type valueType)
Parameters
valueTypeTypeType 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
jsonValueJsonElementJSON value.
typeNamestringType 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
jsonValueJsonElementJSON 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
streamStreamStream to write serialized settings.
valuesIDictionary<SettingKey, object>All keys and values.
metadataSettingsMetadataMetadata.
WriteJsonValue(Utf8JsonWriter, string, object)
Write JSON value according to type name.
protected virtual void WriteJsonValue(Utf8JsonWriter writer, string typeName, object value)
Parameters
writerUtf8JsonWritertypeNamestringType name.
valueobjectValue to write.