Table of Contents

Class MigratingStaticJsonConverter<T>

Namespace
TinyLife
Assembly
Tiny Life.dll

A Newtonsoft.Json.JsonConverter<T> that doesn't actually serialize the object, but instead serializes the name given to it by the underlying Dictionary<TKey, TValue>. Optionally, the name of a Dictionary<TKey, TValue> can be passed to this converter when used in the Newtonsoft.Json.JsonConverterAttribute by passing the arguments for the StaticJsonConverter(Type, string) constructor as Newtonsoft.Json.JsonConverterAttribute.ConverterParameters.

public class MigratingStaticJsonConverter<T> : StaticJsonConverter<T>

Type Parameters

T

The type of the object to convert

Inheritance
JsonConverter
JsonConverter<T>
StaticJsonConverter<T>
MigratingStaticJsonConverter<T>
Inherited Members
StaticJsonConverter<T>.Entries
StaticJsonConverter<T>.Inverse
StaticJsonConverter<T>.ThrowOnRead
StaticJsonConverter<T>.WriteJson(JsonWriter, T, JsonSerializer)
JsonConverter.CanRead
JsonConverter.CanWrite
Extension Methods

Constructors

MigratingStaticJsonConverter(Dictionary<string, T>, bool)

Creates a new static json converter using the given underlying Dictionary<TKey, TValue>.

public MigratingStaticJsonConverter(Dictionary<string, T> entries, bool throwOnRead = false)

Parameters

entries Dictionary<string, T>

The entries, or registry, that this static json converter uses.

throwOnRead bool

Whether to throw a KeyNotFoundException in ReadJson(JsonReader, Type, T, bool, JsonSerializer) if a key is missing, or throw a Newtonsoft.Json.JsonSerializationException if a stored json value is not a string. If this is false, ReadJson(JsonReader, Type, T, bool, JsonSerializer) returns default instead.

MigratingStaticJsonConverter(Type, string)

Creates a new static json converter by finding the underlying Dictionary<TKey, TValue> from the given type and member name

public MigratingStaticJsonConverter(Type type, string memberName)

Parameters

type Type

The type that the dictionary is declared in

memberName string

The name of the dictionary itself

MigratingStaticJsonConverter(Type, string, bool)

Creates a new static json converter by finding the underlying Dictionary<TKey, TValue> from the given type and member name

public MigratingStaticJsonConverter(Type type, string memberName, bool throwOnRead)

Parameters

type Type

The type that the dictionary is declared in

memberName string

The name of the dictionary itself

throwOnRead bool

Whether to throw a KeyNotFoundException in ReadJson(JsonReader, Type, T, bool, JsonSerializer) if a key is missing, or throw a Newtonsoft.Json.JsonSerializationException if a stored json value is not a string. If this is false, ReadJson(JsonReader, Type, T, bool, JsonSerializer) returns default instead.

Methods

ReadJson(JsonReader, Type, T, bool, JsonSerializer)

Reads the JSON representation of the object.

public override T ReadJson(JsonReader reader, Type objectType, T existingValue, bool hasExistingValue, JsonSerializer serializer)

Parameters

reader JsonReader

The Newtonsoft.Json.JsonReader to read from.

objectType Type

Type of the object.

existingValue T

The existing value of object being read. If there is no existing value then null will be used.

hasExistingValue bool

The existing value has a value.

serializer JsonSerializer

The calling serializer.

Returns

T

The object value.