Class DynamoDbEnumAttribute
Says how the converter that the source generator writes for an enum reads a stored name. [DynamoDbEnum(UnknownName = UnknownEnumName.CountsAsMissing)] makes a name the enum does not have, such as one
that a newer version of a service wrote during a rollout, read as if the attribute were not in the item, where it would throw otherwise.
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false, Inherited = false)]
public sealed class DynamoDbEnumAttribute : Attribute
- Inheritance
-
DynamoDbEnumAttribute
- Inherited Members
Remarks
It changes reads alone. A write stores the name of the member as before, so the stored bytes are the same with and without it, and adding it or taking it off needs no migration.
As if the attribute were not in the item means what a read does for that, which is what a converter that answers CountsAsMissing(in DynamoDbReader, AttributeType) gives: a property keeps its
initial value, a nullable one too, so one without an initializer reads as null, a required member throws DynamoDbMappingException, and an input of a key that holds it is
restored from that key. An empty string is no name either, so it counts as missing too. A value that is not a string, such as a number, still throws, because that is no name at all.
It is the property that is lenient, not every place the enum is read. An element of a list, a set or a map still throws for a name the enum does not have: dropping it would give a collection that is shorter than
what is stored, which the next Put of the entity writes back, and a list has positions. A plain key still throws, because a read that took it for missing would give an entity with another key, and
Keys.X.Parse of a key template does not change. Select of the handle gives what it gives for a missing attribute: null for a nullable property, and for any other a throw that DYNA209
reports where it sees the call.
It is for the converter that the generator writes. An enum with a DynamoDbConverterAttribute of its own has no such converter, a [Flags] enum is stored as a number, which has no unknown
name, and DYNA033 reports both. A property with a DynamoDbConverterAttribute, or a type with a DynamoDbDefaultConverterAttribute, reads through that converter and not through
this.
Constructors
DynamoDbEnumAttribute()
public DynamoDbEnumAttribute()
Properties
UnknownName
Gets or sets what a stored name that the enum does not have means, Throw by default. See the remarks of this class.
public UnknownEnumName UnknownName { get; set; }