Skip to content

Serializable Members

kevin-montrose edited this page Apr 10, 2021 · 2 revisions

Serializable Members

Introduction

When writing data, Cesil takes a number of conceptual steps both per-stream and per-row. The configurable pieces of this process are wrapped in the SerializableMember class.

Conceptual Overview

When an IBoundConfiguration<TRow> is created for a static type, Cesil will using the provided Options to:

  1. Discover DeserializableMembers for TRow using ITypeDescriber.EnumerateMembersToDeserialize(TypeInfo)
  2. Discover SerializableMembers for TRow using ITypeDescriber.EnumerateMembersToSerialize(TypeInfo)
  3. Discover the InstanceProvider for TRow using ITypeDescriber.GetInstanceProvider(TypeInfo)

When Cesil begins writing a data stream, it takes the following steps:

  1. Determine if headers need to be written, and write them if so

Then, for each row it writes, Cesil will:

  1. For each member on the row, Cesil will
    1. Call the configured ShouldSerialize, if one is configured, and skip the remaining steps for this cell if it returns false
    2. Call the configured Getter to get the value of the member
    3. If the configured EmitDefaultValue == EmitDefaultValue.No and the value is default, Cesil will skip the remaining steps for this cell
      • For value types, the default value is an instance with all 0 fields
      • For reference types, the default value is null
      • If the cell type implements IEquatable<T>, Equals(T) is used to determine equality
    4. Call the configured Formatter to write the cell value to the stream

Creating SerializableMembers

SerializableMembers exposes many static methods, most of them for convenience.

These families of methods are:

  • ForField(...)
    • Automatically discovers unspecified parameters by looking at the given FieldInfo
  • ForProperty(...)
    • Automatically discovers unspecified parameters by looking at the given PropertyInfo

For each of these convenience methods, all parameters must be non-null.

The base method that backs all of these convenience methods is SerializableMember.Create(TypeInfo, string, Getter, Formatter, ShouldSerialize?, EmitDefaultValue).