Table of Contents

Class OmitEmptyAttribute

Namespace
DynaSharp.Mapping
Assembly
DynaSharp.dll

Treats an empty string or an empty collection like null, so that an item does not fill up with attributes that say nothing. It goes on a string, list, set, dictionary or array property, nullable or not, that feeds no key, or on an entity or document type, where it covers those properties of that type that feed no key. [OmitEmpty(false)] takes it back for a property or a type, where a type or OmitEmpty asked for it.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class OmitEmptyAttribute : Attribute
Inheritance
OmitEmptyAttribute
Inherited Members

Remarks

An empty value is written like null: a Put, a batch, a transaction and From<T>(T) leave the attribute out, Set by handle is a Remove, SetIfNotNull adds nothing, and SetIfNotExists by handle rejects it, as it rejects null. A raw path knows no handle, so it writes what it is given. A condition such as Attrs.Name.Eq("") asks what it says, and finds what other code stored.

Reads do not change. A stored "", written by other code, reads as "", and a missing attribute reads as it always does: a nullable property as null, a set as empty, and anything else keeps its initial value. So an empty value comes back as what the property starts as, which is null for a string? and a filled list for a property that starts with one. Select of a property that is not nullable throws for a missing attribute, which DYNA209 points out, unless it is a set.

That goes for lists, sets, dictionaries and arrays too, so an empty list does not read back as empty: it reads as null or as the initial value. Null and [] can mean different things, such as not asked and asked with no answer, and [OmitEmpty(false)] on the property stores the empty one.

This is wider than the rule of the AWS SDK, which leaves out an empty string and keeps an empty list of documents, an empty dictionary and an empty byte[]. So code that has to store what the SDK stored takes [OmitEmpty(false)] on those.

A key must not be empty, and a read that cannot do without a value could never read an empty one back, which is a required property that is neither nullable nor a set, and a constructor parameter of the same kind without a default. On a type and through OmitEmpty such a property stays written, and on a property, as on anything that is not a string or a collection, this is the error DYNA030. It is not inherited: a derived type says so again, and a nested type has its own, whether a property that holds it says anything or not.

Constructors

OmitEmptyAttribute()

Initializes a new instance of the OmitEmptyAttribute class, which leaves empty values out.

public OmitEmptyAttribute()

OmitEmptyAttribute(bool)

Initializes a new instance of the OmitEmptyAttribute class.

public OmitEmptyAttribute(bool enabled)

Parameters

enabled bool

Whether empty values are left out. False writes them, whatever the type or OmitEmpty says.

Properties

Enabled

Gets a value indicating whether empty values are left out.

public bool Enabled { get; }

Property Value

bool