Table of Contents

Struct HashSetConverter<T, TElement>

Namespace
DynaSharp.Serialization
Assembly
DynaSharp.dll

Converts HashSet<T> to and from a string set, number set or binary set, as TElement says.

public readonly struct HashSetConverter<T, TElement> : IDynamoDbConverter<HashSet<T>>, IAddableConverter where TElement : IDynamoDbSetElementConverter<T>

Type Parameters

T

The element type.

TElement

The converter of the elements, which also decides the kind of set.

Implements
Inherited Members

Remarks

DynamoDB cannot store an empty set and rejects one with a validation error, so a set attribute that may be empty must be left out of the item. The mapping code for entities does that, and reads a missing set attribute as an empty set. This converter writes whatever it is given, for example an empty set that is an element of a list, and a set read from an empty SS is empty as well.

The set that is read has exactly the capacity of its elements and uses the default equality comparer of T. DynamoDB does not keep the order of a set.

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 HashSet<T> Read(ref DynamoDbReader reader, AttributeType type)

Parameters

reader DynamoDbReader

The 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.

type AttributeType

The 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

HashSet<T>

The value.

Exceptions

JsonException

type is not the kind of set TElement reads, or an element fails to read.

TryReadMissing(out HashSet<T>)

Finds out what a read of one attribute gives when the item does not have it. No value is the answer for most types, and the read then throws DynamoDbMappingException rather than make one up. A nullable type answers with null, because null is left out on write, and a set with an empty set, because DynamoDB has none.

static bool TryReadMissing(out HashSet<T> value)

Parameters

value HashSet<T>

The value, if there is one.

Returns

bool

true if a missing attribute has a value of this type.

Remarks

This is infrastructure of Select, which alone asks it, and the built-in converters and the generated handle of a version with Allow answer for themselves. A converter of your own needs it in one case: a converter of a set, because an empty set is a missing attribute in DynamoDB, so without an answer here a Select throws for every item whose set is empty. A read of the entity does not ask this: a property with a converter of your own keeps its initial value, or throws if it is required.

Write(DynamoDbWriter, HashSet<T>)

Writes a value as one complete attribute value, for example with WriteNumber<T>(T).

static void Write(DynamoDbWriter writer, HashSet<T> value)

Parameters

writer DynamoDbWriter

The 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.

value HashSet<T>

The value.

Exceptions

ArgumentNullException

value is null.

InvalidOperationException

TElement does not return a set type from SetType.