-
-
Notifications
You must be signed in to change notification settings - Fork 3
Serializable Members
kevin-montrose edited this page Apr 10, 2021
·
2 revisions
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.
When an IBoundConfiguration<TRow>
is created for a static type, Cesil will using the provided Options to:
- Discover
DeserializableMembers
forTRow
usingITypeDescriber.EnumerateMembersToDeserialize(TypeInfo)
- Discover
SerializableMembers
forTRow
usingITypeDescriber.EnumerateMembersToSerialize(TypeInfo)
- Discover the InstanceProvider for
TRow
usingITypeDescriber.GetInstanceProvider(TypeInfo)
When Cesil begins writing a data stream, it takes the following steps:
- Determine if headers need to be written, and write them if so
Then, for each row it writes, Cesil will:
- For each member on the row, Cesil will
- Call the configured ShouldSerialize, if one is configured, and skip the remaining steps for this cell if it returns
false
- Call the configured Getter to get the value of the member
- 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
- Call the configured Formatter to write the cell value to the stream
- Call the configured ShouldSerialize, if one is configured, and skip the remaining steps for this cell if it returns
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
- Automatically discovers unspecified parameters by looking at the given
-
ForProperty(...)
- Automatically discovers unspecified parameters by looking at the given
PropertyInfo
- Automatically discovers unspecified parameters by looking at the given
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)
.