Table of Contents

Class CsvReaderOptions

Namespace
ExcelReader.Core.Reader.Csv
Assembly
ExcelReader.Core.dll

The delimited-text settings for a CSV source, carried by Csv.

public sealed record CsvReaderOptions : IEquatable<CsvReaderOptions>
Inheritance
CsvReaderOptions
Implements
Inherited Members

Remarks

Size limits and string interning come from ExcelReaderOptions, as for every other format.

Properties

Default

Gets the default options instance, used whenever a CsvReader is opened without explicit options.

public static CsvReaderOptions Default { get; }

Property Value

CsvReaderOptions

Delimiter

Gets the byte used to separate fields within a record. Defaults to ,.

public byte Delimiter { get; init; }

Property Value

byte

DetectEncodingFromByteOrderMark

Gets a value indicating whether a leading UTF-8 byte-order mark should be detected and skipped. Defaults to true.

public bool DetectEncodingFromByteOrderMark { get; init; }

Property Value

bool

Encoding

Gets the source's text encoding. When not null, the source is transcoded to UTF-8 as it is read. Defaults to null, meaning the source is already UTF-8.

public Encoding? Encoding { get; init; }

Property Value

Encoding

Remarks

Non-UTF-8 sources (e.g. Windows-1252 exports) are transcoded at open time, so the scanner itself always works in UTF-8.

Quote

Gets the byte used to quote fields. Defaults to ".

public byte Quote { get; init; }

Property Value

byte

SniffDialect

Gets a value indicating whether the source's dialect is inferred from a sample of its leading bytes at open time, replacing Delimiter and Quote with what CsvSniffer reports. Defaults to false.

public bool SniffDialect { get; init; }

Property Value

bool

Remarks

Applied by the entry points that own the source — FromCsvFile(string, ExcelReaderOptions?) and the other Excel.FromCsv* factories, Open(string, ExcelFileFormat, ExcelReaderOptions?) with Csv, and the parallel CSV entry points — since the sample has to be read before the reader starts. An explicitly set Encoding is kept unless the source carries a byte-order mark naming a different one. Sniffing a stream reads a sample and restores the position, so it requires a seekable stream.

Methods

WithDialect(CsvDialect)

Returns a copy of these options with the delimiter, quote, and encoding of the given dialect.

public CsvReaderOptions WithDialect(CsvDialect dialect)

Parameters

dialect CsvDialect

The dialect to apply, typically produced by Detect(ReadOnlySpan<byte>, CsvSnifferOptions?).

Returns

CsvReaderOptions