public abstract class CsvRecordWriter<T>
Namespace
CsvHelper
Assembly
CsvHelper.dll
Builds
net10.0 netstandard2.1 netstandard2.0 net47

Remarks

A record writer does not depend on the CsvWriter it writes to and does not change after it is created, so it can be used with any writer, on any thread.

To write one by hand, write the column names in WriteHeader (with WriteColumnName, which puts ColumnPrefix in front) and the fields of a record in Write, as many as FieldCount says, with the writer's WriteField methods. Neither ends the record. Register it with CsvRecordWriter.Register.

Constructors

CsvRecordWriter(string)

Added in v34.0.0
protected CsvRecordWriter(string columnPrefix)

Creates a record writer that puts columnPrefix in front of the names of its columns.

Parameters

columnPrefixstring
The text in front of each column name, such as "Ship ", for a record written as a member of another record (CsvColumnAttribute.Prefix); "" for none.

Exceptions

ArgumentNullException
columnPrefix is null.

View source

Properties

Methods

protected CsvRecordWriter<TNested> NestedWriter<TNested>(string prefix)

Creates the record writer of a member whose type is itself a record type, which writes its columns in the same records, with ColumnPrefix and then prefix in front of their names.

Type parameters

TNested
The type of the member.

Parameters

prefixstring
The text in front of the nested record's column names (CsvColumnAttribute.Prefix); "" for none.

Returns

CsvRecordWriter<TNested>
The record writer of TNested.

Exceptions

ArgumentNullException
prefix is null.
InvalidOperationException
TNested has no record writer, or its records cannot be written, or the nested record writers lead back to their own type without end.

View source

Write(CsvWriter, T)

Added in v34.0.0abstract
public abstract void Write(CsvWriter writer, T record)

Writes the values of a record as fields of the current record, without ending it.

Parameters

writerCsvWriter
The writer.
recordT
The record; not null.

View source