Table of Contents

Interface ISheetRowMapper<T>

Namespace
SheetStream
Assembly
SheetStream.dll

Describes how a type maps to worksheet columns and moves values in both directions without reflection. LoadFromCollection uses it to write rows and ExcelReader.Read<T> to bind them back. Implementations are generated at compile time for types marked with SheetRowAttribute, but a hand-written mapper works just as well; register it with Register<T>(ISheetRowMapper<T>) or pass it to the explicit overloads.

public interface ISheetRowMapper<T>

Type Parameters

T

The row type.

Remarks

Columns are zero-based and ordered exactly as they appear in the sheet: by [SheetColumn(Order)] ascending, then declaration order. A mapper must be stateless and safe to share between threads.

Properties

CanRead

True when Create() can build a new instance, so the mapper can be used for reading.

bool CanRead { get; }

Property Value

bool

Headers

Header text per column, in column order.

IReadOnlyList<string> Headers { get; }

Property Value

IReadOnlyList<string>

NumberFormats

Excel number format per column (from [SheetColumn(NumberFormat)]), or null for the default.

IReadOnlyList<string?> NumberFormats { get; }

Property Value

IReadOnlyList<string>

Methods

CanSet(int)

True when SetValue(ref T, int, object?) can assign the column (false for read-only, init-only or get-only members).

bool CanSet(int column)

Parameters

column int

Returns

bool

Create()

Creates an empty instance to fill while reading. Throws NotSupportedException when CanRead is false.

T Create()

Returns

T

FindColumn(string)

Resolves a header read from a sheet to a column index, or -1 when no settable member matches. Matching is case-insensitive and accepts the [SheetColumn] name, the [DisplayName] and the member name, like the reflection-based reader does.

int FindColumn(string header)

Parameters

header string

Returns

int

GetValue(T, int)

Reads one member as an object; a convenience for callers that need values outside a row writer.

object? GetValue(T item, int column)

Parameters

item T
column int

Returns

object

MemberType(int)

The declared type of the member behind a column, used to convert cell values when reading.

Type MemberType(int column)

Parameters

column int

Returns

Type

SetValue(ref T, int, object?)

Assigns an already converted value (of MemberType(int), or null) to a column. Columns where CanSet(int) is false are ignored. item is passed by reference so the same mapper works for structs.

void SetValue(ref T item, int column, object? value)

Parameters

item T
column int
value object

WriteRow(T, RowWriter, CellStyle?[])

Writes every column of item into row using the typed WriteCell(double, CellStyle?) overloads, so no value is boxed per cell. styles has one entry per column (null for the default style).

void WriteRow(T item, RowWriter row, CellStyle?[] styles)

Parameters

item T
row RowWriter
styles CellStyle[]