Class ExcelParser
Creates ExcelParser<T> instances.
public static class ExcelParser
- Inheritance
-
ExcelParser
- Inherited Members
Methods
BuildWithAttributeFallback<T>(Action<ExcelRowMapBuilder<T>>, ExcelParserOptions?)
Creates a parser whose map merges configure's bindings with attribute-driven
ones reflected from T: a builder binding fully replaces every
attribute-driven property that shares one of its header names, and every other property keeps
its attribute-driven behavior.
[RequiresUnreferencedCode("BuildWithAttributeFallback reflects over T's public properties for the attribute-driven fallback, which trimming may remove.")]
[RequiresDynamicCode("BuildWithAttributeFallback binds attribute-driven property setters at runtime (MethodInfo.CreateDelegate / MakeGenericMethod).")]
public static ExcelParser<T> BuildWithAttributeFallback<T>(Action<ExcelRowMapBuilder<T>> configure, ExcelParserOptions? options = null) where T : allows ref struct
Parameters
configureAction<ExcelRowMapBuilder<T>>Configures the properties that should override their attribute-driven binding.
optionsExcelParserOptionsHeader matching, culture and parse-failure options. Defaults to a new ExcelParserOptions.
Returns
- ExcelParser<T>
The parser.
Type Parameters
TThe model type.
Remarks
The match is by header name, not by property identity — the builder only receives a setter
lambda. To override property P, configure the builder with one of the header names
P's [ExcelColumn] attributes already use. Configuring a different header
name for P overrides nothing: both bindings survive and P is assigned twice per row.
Mark such a property [ExcelIgnore] instead.
Exceptions
- ArgumentNullException
configureis null.- ArgumentOutOfRangeException
optionshas HeaderRow less than 1.- InvalidOperationException
configurecalls PropertyAt<TValue>(int, ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool): an index-based map has no header row to match attribute-driven properties against.
Build<T>(Action<ExcelRowMapBuilder<T>>, ExcelParserOptions?)
Creates a parser whose map comes entirely from configure. Trimming and AOT safe.
public static ExcelParser<T> Build<T>(Action<ExcelRowMapBuilder<T>> configure, ExcelParserOptions? options = null) where T : allows ref struct
Parameters
configureAction<ExcelRowMapBuilder<T>>Configures the row map by calling Property<TValue>(string[], ExcelCellReader<TValue>, ExcelPropertySetter<T, TValue>, bool, bool) and its siblings.
optionsExcelParserOptionsHeader matching, culture and parse-failure options. Defaults to a new ExcelParserOptions.
Returns
- ExcelParser<T>
The parser.
Type Parameters
TThe model type.
Remarks
For when the mapping is a runtime decision — loaded from config, chosen by a user, or different
per input file. Each call builds its own map, so two parsers configured differently for the same
T coexist.
Exceptions
- ArgumentNullException
configureis null.- ArgumentOutOfRangeException
optionshas HeaderRow less than 1.
FromAttributes<T>(ExcelParserOptions?)
Creates a parser that binds header columns to T's properties decorated with
[ExcelColumn]/[ExcelRequired]/[ExcelConverter], found by reflection.
[RequiresUnreferencedCode("Typed parsing reflects over T's public properties, which trimming may remove.")]
[RequiresDynamicCode("Typed parsing binds property setters at runtime (MethodInfo.CreateDelegate / MakeGenericMethod).")]
public static ExcelParser<T> FromAttributes<T>(ExcelParserOptions? options = null) where T : allows ref struct
Parameters
optionsExcelParserOptionsHeader matching, culture and parse-failure options. Defaults to a new ExcelParserOptions.
Returns
- ExcelParser<T>
The parser.
Type Parameters
TThe model type.
Remarks
Not compatible with Native AOT, and trimming can remove the properties it binds to. Use Generated<T>(ExcelParserOptions?) or Build<T>(Action<ExcelRowMapBuilder<T>>, ExcelParserOptions?) instead where that matters. CSV readers get a separate map with text-based date parsing.
Exceptions
- ArgumentOutOfRangeException
optionshas HeaderRow less than 1.
Generated<T>(ExcelParserOptions?)
Creates a parser from the map the [ExcelSerializable] source generator emitted for T. Trimming and AOT safe.
public static ExcelParser<T> Generated<T>(ExcelParserOptions? options = null) where T : IExcelRowMap<T>, allows ref struct
Parameters
optionsExcelParserOptionsHeader matching, culture and parse-failure options. Defaults to a new ExcelParserOptions.
Returns
- ExcelParser<T>
The parser.
Type Parameters
TThe model type; must implement IExcelRowMap<T>.
Remarks
The map is built once and reused for every reader, CSV included. The generator binds
DateTime/DateOnly/TimeOnly properties with the
*Auto readers in ExcelCellReaders — serial number first, text as a fallback.
Exceptions
- ArgumentOutOfRangeException
optionshas HeaderRow less than 1.