Class DictionaryJsonConverter<TKey, TValue>

Namespace
Cratis.Json
Assembly
Cratis.Fundamentals.dll

Represents a JsonConverter for converting dictionaries to and from JSON.

public abstract class DictionaryJsonConverter<TKey, TValue> : JsonConverter<IDictionary<TKey, TValue>> where TKey : notnull

Type Parameters

TKey

Key of the dictionary.

TValue

Value of the dictionary.

Inheritance
JsonConverter<IDictionary<TKey, TValue>>
DictionaryJsonConverter<TKey, TValue>
Inherited Members
Extension Methods

Constructors

DictionaryJsonConverter()

protected DictionaryJsonConverter()

Methods

GetKeyFromString(string)

Get the key instance from the string representation.

protected abstract TKey GetKeyFromString(string key)

Parameters

key string

String representation of the key.

Returns

TKey

New key instance.

GetKeyString(TKey)

Get the string representation of the key.

protected virtual string GetKeyString(TKey key)

Parameters

key TKey

Key to get from.

Returns

string

String representation.

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Dictionary JSON deserialization uses well-known types that are preserved.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Dictionary JSON deserialization uses well-known types that are safe for AOT.")]
public override IDictionary<TKey, TValue>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader
typeToConvert Type
options JsonSerializerOptions

Returns

IDictionary<TKey, TValue>

Write(Utf8JsonWriter, IDictionary<TKey, TValue>, JsonSerializerOptions)

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Dictionary JSON serialization uses well-known types that are preserved.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Dictionary JSON serialization uses well-known types that are safe for AOT.")]
public override void Write(Utf8JsonWriter writer, IDictionary<TKey, TValue> value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter
value IDictionary<TKey, TValue>
options JsonSerializerOptions