Configure a layout fluently¶
FileConfiguration<T> plus FileLayoutBuilder offer a code-first alternative to the attribute-based layout declared for Read a typed flat file and Write a typed flat file, letting a consumer describe format and per-property layout with a fluent API instead of class/property attributes.
| Field | Value |
|---|---|
| Operation ID | OP-04 |
| Trigger | A consumer subclasses FileConfiguration<T> and calls the protected builder methods in its constructor.* |
| Inputs | Lambda property expressions. |
| Outputs | An IFileConfiguration usable by the read (OP-01) and write (OP-03) operations. |
| Primary components | FileConfiguration<T>, FileLayoutBuilder |
| Entry point | Common\SAIF.Common.Files\Core\Configurations\FileConfiguration.cs, Common\SAIF.Common.Files\Core\Configurations\FileLayoutBuilder.cs |
Steps¶
- Fix the format — the constructor sets
Format, marksIsDefault = true, and derives the delimiter forCsv/TabDelimited. - Bind the record and index properties —
Record(x => x.Value)/Index(x => x.Index)resolvePropertyInfovia the delegatedSAIF.Framework.CommonextensionExpressionExtensions.GetPropertyInfo(traced source:Common\SAIF.Common\Extensions\ExpressionExtensions.cs). - Declare a layout —
Layout(x => x.PropertyName)(constrained toIConvertible) orCustomLayout()appends aFileRecordLayoutwith a sequentialIdand returns anIFileLayoutBuilder. - Chain builder calls to set element/fixed position, format string, title, id, trim, alignment/padding, read/write direction, and converter delegates.
ReadCustomforces the layout read-only;WriteCustomforces it write-only (BR-016).
Process flow¶
flowchart TD
Start(["Consumer subclasses<br>FileConfiguration<T>"]) --> Fix["Constructor fixes Format /<br>IsDefault / delimiter"]
Fix --> Bind["Record(x => x.Value) /<br>Index(x => x.Index)<br>resolve PropertyInfo"]
Bind --> Layout["Layout(x => x.PropertyName) /<br>CustomLayout()<br>appends FileRecordLayout"]
Layout --> Chain["Chained builder calls set<br>position, format, title,<br>trim, alignment, converters, direction"]
Chain --> EndOk(["IFileConfiguration ready<br>for OP-01 / OP-03"])
Failure and edge-case behavior¶
- A layout marked
ReadCustomis excluded from the writable-layout set, and one markedWriteCustomis excluded from the readable-layout set, so a caller that expects bidirectional mapping from a one-directional custom layout will silently see the property omitted on the opposite operation (BR-016).
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
- Common\SAIF.Common.Files\Core\Configurations\FileConfiguration.cs
- Common\SAIF.Common.Files\Core\Configurations\FileLayoutBuilder.cs
- Common\SAIF.Common.Files\Core\Configurations\FileRecordLayout.cs
- Common\SAIF.Common\Extensions\ExpressionExtensions.cs