Table of Contents

Struct ReadOnlySetConverter<T, TElement>

Namespace
DynaSharp.Serialization
Assembly
DynaSharp.dll

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

public readonly struct ReadOnlySetConverter<T, TElement> : IDynamoDbConverter<IReadOnlySet<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

See HashSetConverter<T, TElement> for the rules of sets. A set that is read is a HashSet<T>. 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 IReadOnlySet<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

IReadOnlySet<T>

The value.

Exceptions

JsonException

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

TryReadMissing(out IReadOnlySet<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 IReadOnlySet<T> value)

Parameters

value IReadOnlySet<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, IReadOnlySet<T>)

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

static void Write(DynamoDbWriter writer, IReadOnlySet<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 IReadOnlySet<T>

The value.

Exceptions

ArgumentNullException

value is null.

InvalidOperationException

TElement does not return a set type from SetType.