Skip to content

Deserializable Members

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

Deserializable Members

Introduction

When reading data, Cesil takes a number of conceptual steps both per-stream and per-row. The configurable pieces of this process are wrapped in the DeserializableMember 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 reading a data stream, it takes the following steps:

  1. Determine the row ending for the data, if not specified
    • This may read some data
  2. Determine if a header row is present, if not specified
    • This may read some data
    • If headers are present, columns discovered earlier may be re-ordered to match what's in the stream

Then, for each row it reads, Cesil will:

  1. Acquire an instance of TRow
  2. Then, for each cell Cesil will
    1. Find the appropriate member to set, based on order
    2. Call the configured Parser with the character data in the cell
    3. Call the configured Reset, if present
    4. Call the configured Setter
  3. Yield the row as appropriate for the called method on IReader<TRow> or IAsyncReader<TRow>

DeserializableMembers 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 convience methods is DeserializableMember.Create(TypeInfo, string, Setter, Parser, MemberRequired, Reset?).

Clone this wiki locally