Table of Contents

Struct NullableConverter<T, TConverter>

Namespace
DynaSharp.Serialization
Assembly
DynaSharp.dll

Converts T? for a value type T: the value in the form of TConverter, or the null value {"NULL":true}.

public readonly struct NullableConverter<T, TConverter> : IDynamoDbConverter<T?> where T : struct where TConverter : IDynamoDbConverter<T>

Type Parameters

T

The underlying value type.

TConverter

The converter of T.

Implements
Inherited Members

Remarks

Writing null produces {"NULL":true}, which is a value, not a missing attribute: it is what a null element of a list becomes. The mapping code for entities leaves a property that is null out instead. Reading accepts the null value, and everything TConverter accepts. Infrastructure: compatible only within a package version, because generated code comes from the generator of the same package.

Methods

CountsAsMissing(in DynamoDbReader, AttributeType)

public static bool CountsAsMissing(in DynamoDbReader reader, AttributeType type)

Parameters

reader DynamoDbReader
type AttributeType

Returns

bool

Explicit Interface Implementations

Read(ref DynamoDbReader, AttributeType)

Reads the attribute value the reader is positioned on.

static 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

T?

The value.

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

Parameters

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

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

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

The value.