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
-
JsonConverterJsonConverter<T>StaticJsonConverter<T>MigratingStaticJsonConverter<T>
- Inherited Members
-
StaticJsonConverter<T>.EntriesStaticJsonConverter<T>.InverseStaticJsonConverter<T>.ThrowOnReadStaticJsonConverter<T>.WriteJson(JsonWriter, T, JsonSerializer)JsonConverter.CanReadJsonConverter.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
boolWhether 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
TypeThe type that the dictionary is declared in
memberName
stringThe 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
TypeThe type that the dictionary is declared in
memberName
stringThe name of the dictionary itself
throwOnRead
boolWhether 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
JsonReaderThe Newtonsoft.Json.JsonReader to read from.
objectType
TypeType of the object.
existingValue
TThe existing value of object being read. If there is no existing value then
null
will be used.hasExistingValue
boolThe existing value has a value.
serializer
JsonSerializerThe calling serializer.
Returns
- T
The object value.