Struct DictionaryConverter<T, TConverter>
- Namespace
- DynaSharp.Serialization
- Assembly
- DynaSharp.dll
Converts Dictionary<TKey, TValue> with string keys to and from a map value (M), each value in the form of TConverter.
public readonly struct DictionaryConverter<T, TConverter> : IDynamoDbConverter<Dictionary<string, T>> where TConverter : IDynamoDbConverter<T>
Type Parameters
TThe value type.
TConverterThe converter of the values.
- Implements
- Inherited Members
Remarks
The keys are the attribute names of the map, so they are always strings; DynamoDB allows an empty name inside a map, and names are compared ordinally. DynamoDB does not keep the order of a map.
The dictionary that is read has exactly the capacity of its entries. A name that appears twice, which DynamoDB never sends, keeps its last value.
Infrastructure: compatible only within a package version, because generated code comes from the generator of the same package.
Explicit Interface Implementations
Read(ref DynamoDbReader, AttributeType)
Reads the attribute value the reader is positioned on.
static Dictionary<string, T> Read(ref DynamoDbReader reader, AttributeType type)
Parameters
readerDynamoDbReaderThe reader, positioned on the value after ReadStartAttribute() or TryReadStartAttribute(out AttributeType). The caller reads the closing brace afterwards, so the converter must read the value completely (all elements of a list, map or set) and nothing more.
typeAttributeTypeThe DynamoDB type of the value. Check it with Expect(AttributeType, AttributeType), which throws JsonException for types the converter does not support. Null is passed to the converter too, so it can map it to null where that makes sense.
Returns
- Dictionary<string, T>
The value.
Exceptions
- JsonException
typeis not Map, or a value fails to read.
Write(DynamoDbWriter, Dictionary<string, T>)
Writes a value as one complete attribute value, for example with WriteNumber<T>(T).
static void Write(DynamoDbWriter writer, Dictionary<string, T> value)
Parameters
writerDynamoDbWriterThe writer, positioned where a value is expected (after an attribute name, or inside a list). It is a ref struct, so it is never null and needs no check.
valueDictionary<string, T>The value.
Exceptions
- ArgumentNullException
valueis null.