Table of Contents

Class ExcelRowMapBuilder<T>

Namespace
ExcelReader.Core.Parser
Assembly
ExcelReader.Core.dll

Accumulates a row-to-property binding for T, fed either by the source generator (feature A) or by a hand-written IExcelRowMap<T> implementation. Mirrors, without reflection, exactly what TypeMapper<T>.Build() produces from attributes.

public sealed class ExcelRowMapBuilder<T> where T : allows ref struct

Type Parameters

T

The row model type being mapped.

Inheritance
ExcelRowMapBuilder<T>
Inherited Members

Methods

Converted<TValue>(string[], IExcelCellConverter<TValue>, ExcelPropertySetter<T, TValue>, bool, bool)

Binds a property to one or more header names via a [ExcelConverter]-style converter, for value types none of the built-in ExcelCellReaders cover. The generator emits new MyConverter() for converter — nothing here uses Activator.

public ExcelRowMapBuilder<T> Converted<TValue>(string[] names, IExcelCellConverter<TValue> converter, ExcelPropertySetter<T, TValue> set, bool isRequired = false, bool requireValue = false)

Parameters

names string[]

The header name(s) that bind to this property; the first is used in error messages.

converter IExcelCellConverter<TValue>

Converts a matched, non-empty cell into a TValue.

set ExcelPropertySetter<T, TValue>

Assigns the converted value to the property.

isRequired bool

Whether the header must be present.

requireValue bool

Whether every data row's cell for this column must also be non-empty.

Returns

ExcelRowMapBuilder<T>

This builder, for chaining.

Type Parameters

TValue

The property's value type.

Factory(Func<T>?)

Sets the factory used to create a fresh T instance per row. null means default(T) — use this for a plain struct with no explicit parameterless constructor, matching TypeMapper<T>.Build()'s own rule. Not calling this method at all has the same effect as calling it with null, which is wrong for any class or struct with an explicit constructor to run — always call it for those.

public ExcelRowMapBuilder<T> Factory(Func<T>? factory)

Parameters

factory Func<T>

The instance factory, or null to use default(T).

Returns

ExcelRowMapBuilder<T>

This builder, for chaining.

PropertyAt<TValue>(int, ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool)

Binds a property to a fixed 0-based column index instead of a header name, so rows with no header at all (or a header the caller doesn't want matched by text) can still be mapped.

public ExcelRowMapBuilder<T> PropertyAt<TValue>(int columnIndex, ExcelCellReader<TValue> read, ExcelPropertySetter<T, TValue> set, bool requireValue = false)

Parameters

columnIndex int

The 0-based column index to read from.

read ExcelCellReader<TValue>

Converts a matched, non-empty cell into a TValue; see ExcelCellReaders for the built-in readers.

set ExcelPropertySetter<T, TValue>

Assigns the read value to the property.

requireValue bool

Whether the cell at columnIndex must be non-empty in every data row.

Returns

ExcelRowMapBuilder<T>

This builder, for chaining.

Type Parameters

TValue

The property's value type.

Remarks

A builder that uses this method exclusively produces a map with no header-row step at all — the first row is already a data row. Mixing this with Property<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool, bool)/ PropertyNullable<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue?>, bool, bool)/Converted<TValue>(string[], IExcelCellConverter<TValue>, ExcelPropertySetter<T, TValue>, bool, bool) on the same builder is not supported, since one map can't both wait for a header row and skip it.

PropertyNullable<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue?>, bool, bool)

Binds a Nullable<T> property to one or more header names, using read — one of the non-nullable built-in readers, e.g. Bool or Parsable<TValue>(in Cell, in ExcelRowContext, out TValue) — to convert the matched cell, then wraps the result in Nullable<T> before calling set. There is no nullable-returning counterpart of the built-in readers to plug into Property<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool, bool) directly, because the wrapping step is identical for every value type — this method does it once, generically.

public ExcelRowMapBuilder<T> PropertyNullable<TValue>(string[] names, ExcelCellReader<TValue> read, ExcelPropertySetter<T, TValue?> set, bool isRequired = false, bool requireValue = false) where TValue : struct

Parameters

names string[]

The header name(s) that bind to this property; the first is used in error messages.

read ExcelCellReader<TValue>

Converts a matched, non-empty cell into a TValue.

set ExcelPropertySetter<T, TValue?>

Assigns the read value, wrapped in Nullable<T>, to the property.

isRequired bool

Whether the header must be present.

requireValue bool

Whether every data row's cell for this column must also be non-empty.

Returns

ExcelRowMapBuilder<T>

This builder, for chaining.

Type Parameters

TValue

The property's underlying (non-nullable) value type.

PropertyRaw(string[], ExcelRowParser<T>, bool, bool)

Binds a header to a single already-fused read+assign delegate, instead of the separate ExcelCellReader<TValue> + ExcelPropertySetter<TModel, TValue> pair Property<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool, bool)/PropertyNullable<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue?>, bool, bool) compose internally. Every bound cell costs one indirect call instead of two (read, then set) — the source generator uses this for [ExcelSerializable] models. Prefer Property<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool, bool) for hand-written maps unless the extra call genuinely matters for your workload; it's a small, row-count-proportional cost, not a correctness concern either way.

public ExcelRowMapBuilder<T> PropertyRaw(string[] names, ExcelRowParser<T> parse, bool isRequired = false, bool requireValue = false)

Parameters

names string[]

The header name(s) that bind to this property; the first is used in error messages.

parse ExcelRowParser<T>

Reads a matched, non-empty cell and assigns it directly onto the model.

isRequired bool

Whether the header must be present.

requireValue bool

Whether every data row's cell for this column must also be non-empty.

Returns

ExcelRowMapBuilder<T>

This builder, for chaining.

Property<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool, bool)

Binds a property to one or more header names, using read to convert the matched cell and set to assign the result.

public ExcelRowMapBuilder<T> Property<TValue>(string[] names, ExcelCellReader<TValue> read, ExcelPropertySetter<T, TValue> set, bool isRequired = false, bool requireValue = false)

Parameters

names string[]

The header name(s) that bind to this property; the first is used in error messages.

read ExcelCellReader<TValue>

Converts a matched, non-empty cell into a TValue; see ExcelCellReaders for the built-in readers.

set ExcelPropertySetter<T, TValue>

Assigns the read value to the property.

isRequired bool

Whether the header must be present.

requireValue bool

Whether every data row's cell for this column must also be non-empty.

Returns

ExcelRowMapBuilder<T>

This builder, for chaining.

Type Parameters

TValue

The property's value type.