Class MigratingStaticJsonConverter<T>
- Namespace
- TinyLife
- Assembly
- TinyLife.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
TThe 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
entriesDictionary<string, T>The entries, or registry, that this static json converter uses.
throwOnReadboolWhether 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
typeTypeThe type that the dictionary is declared in
memberNamestringThe 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
typeTypeThe type that the dictionary is declared in
memberNamestringThe name of the dictionary itself
throwOnReadboolWhether 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
readerJsonReaderThe Newtonsoft.Json.JsonReader to read from.
objectTypeTypeType of the object.
existingValueTThe existing value of object being read. If there is no existing value then
nullwill be used.hasExistingValueboolThe existing value has a value.
serializerJsonSerializerThe calling serializer.
Returns
- T
The object value.