CsvRecordMapper()
protected CsvRecordMapper()Creates a mapper whose columns are looked up by their own names.
Class in CsvHelper
Reads records of type T from the columns of one reader's header. The CsvHelper source generator writes one for each CsvRecordAttribute type; CsvRecordMapper.Create<T>(CsvReader) creates it.
public abstract class CsvRecordMapper<T>CsvHelperCsvHelper.dllA mapper resolves its columns when it is created and does not change afterwards, so it can read records of any reader with the same columns, on any thread (the workers of CsvReader.ParallelEnumerate<T>(int) share one).
To write one by hand, find the columns in the constructor with Column(CsvReader, string, int, bool, string), call ThrowIfColumnsMissing, and read the fields with the reader's CsvReader.GetString(int) and CsvReader.Parse<T>(int) in Read(CsvReader). Register it with CsvRecordMapper.Register<T>(Func<CsvReader, CsvRecordMapper<T>>), or put a CsvConverterAttribute naming it on T.
protected CsvRecordMapper()Creates a mapper whose columns are looked up by their own names.
protected CsvRecordMapper(string columnPrefix)Creates a mapper that puts columnPrefix in front of the names it looks up.
columnPrefixstring"Ship ", for a record read as a member of another record (CsvColumnAttribute.Prefix); "" for none.columnPrefix is null.protected string ColumnPrefix { get; }The text that Column(CsvReader, string, int, bool, string) puts in front of each header name; "" for none.
protected int Column(CsvReader reader, string name, int index, bool optional, string member)Finds the column of a member: index when it is not negative, else the header column called ColumnPrefix followed by name. Missing required columns are reported together by ThrowIfColumnsMissing.
readerCsvReadernamestringindexintname.optionalboolmemberstringprotected int Column(CsvReader reader, string[] names, int index, bool optional, string member)Finds the column of a member that can have several names: index when it is not negative, else the header column called ColumnPrefix followed by the first of names that the header has. Missing required columns are reported together by ThrowIfColumnsMissing.
readerCsvReadernamesstring[]indexintnames.optionalboolmemberstringnames is null.protected int Column(CsvReader reader, string[] names, int nameIndex, int index, bool optional, string member)Finds the column of a member among several columns with the same name: index when it is not negative, else the one at nameIndex among the header columns called ColumnPrefix followed by one of names (the first name that the header has that many times). Missing required columns are reported together by ThrowIfColumnsMissing.
readerCsvReadernamesstring[]nameIndexintindexintnames.optionalboolmemberstringnames is null.nameIndex is negative.protected string[] ColumnNames(CsvReader reader, int start, int end, string member)The header names of the columns from start to end, the keys of a dictionary member that reads them.
readerCsvReaderstartintendintmemberstringreader is null.start is negative.protected int[] Columns(CsvReader reader, string[] names, bool optional, string member)Finds the columns of a collection member: every header column called ColumnPrefix followed by the first of names that the header has, in order, for files that repeat a column name. Without any, a required member is reported by ThrowIfColumnsMissing.
readerCsvReadernamesstring[]optionalboolmemberstringnames is null.public virtual string? FindFailingMember(CsvReader reader, out int fieldIndex)After Read(CsvReader) threw for the current record, finds the member whose field made it throw, by reading the members again one at a time. The record methods of CsvReader call it to say where a record failed (CsvFormatException.Member), so reading costs nothing more until a record fails. Generated mappers implement it; this implementation finds nothing.
readerCsvReaderfieldIndexintOrder.Price), or null when every member reads on its own, such as when the constructor or a setter threw.protected CsvRecordMapper<TNested> NestedMapper<TNested>(CsvReader reader, string prefix)Creates the mapper of a member whose type is itself a record type, which reads its columns from the same records, with ColumnPrefix and then prefix in front of their names. Its missing required columns are reported with this mapper's by ThrowIfColumnsMissing.
TNestedreaderCsvReaderprefixstring"" for none.prefix is null.TNested has no mapper, or its mapper does not support column prefixes and the prefix is not empty, or the nested mappers lead back to their own type without end.public abstract T Read(CsvReader reader)Reads the current record of reader.
readerCsvReaderT with the values of the record.public virtual void Read(CsvReader reader, T record)Reads the current record of reader into record, an existing instance, for CsvReader.EnumerateRecords. Generated mappers implement it for classes whose members can all be set after construction; this implementation throws.
readerCsvReaderrecordTprotected void ThrowIfColumnsMissing(CsvReader reader)Throws a KeyNotFoundException naming every required column that Column(CsvReader, string, int, bool, string) and NestedMapper did not find, if there are any.
readerCsvReader