public static class CsvRecordWriter
Namespace
CsvHelper
Assembly
CsvHelper.dll
Builds
net10.0 netstandard2.1 netstandard2.0 net47

Methods

Create<T>()

Added in v34.0.0static
public static CsvRecordWriter<T> Create<T>()

Creates the record writer of T.

Type parameters

T
The type of the records.

Returns

CsvRecordWriter<T>
A record writer, which can be used with any CsvWriter.

Exceptions

InvalidOperationException
T is not a CsvRecordAttribute type and has no registered record writer, or its records cannot be written (the message says why), or its nested record writers lead back to their own type without end (records nest at most 64 deep).

View source

Create<T>(string)

Added in v34.0.0static
public static CsvRecordWriter<T> Create<T>(string columnPrefix)

Creates the record writer of T that puts columnPrefix in front of its column names.

Type parameters

T
The type of the records.

Parameters

columnPrefixstring
The text in front of each column name, such as "Ship "; "" for none.

Returns

CsvRecordWriter<T>
A record writer, which can be used with any CsvWriter.

Exceptions

ArgumentNullException
columnPrefix is null.
InvalidOperationException
T is not a CsvRecordAttribute type and has no registered record writer, or its records cannot be written (the message says why), or its nested record writers lead back to their own type without end (records nest at most 64 deep).

View source

IsRegistered<T>()

Added in v34.0.0static
public static bool IsRegistered<T>()

Whether T has a record writer, generated or registered, so that Create<T>() does not throw for want of one. (A generated writer may still throw when the type's records cannot be written, with the reason.)

Type parameters

T
The type of the records.

Returns

bool
true when a factory is registered for the type.

View source

public static void Register<T>(Func<string, CsvRecordWriter<T>> factory)

Registers the record writer factory of T, such as a hand-written CsvRecordWriter<T>. Code generated for CsvRecordAttribute types calls this when their assembly is loaded. A later registration for the same type replaces an earlier one.

Type parameters

T
The type of the records.

Parameters

factoryFunc<string, CsvRecordWriter<T>>
Creates a record writer that puts the given text in front of its column names (CsvRecordWriter<T>.ColumnPrefix).

Exceptions

ArgumentNullException
factory is null.

View source