Table of Contents

DelimitedReaderOptions Struct

Definition

Namespace
Bodu.Text.Delimited.Reader
Assembly
Bodu.Text.Delimited.dll
Package
Bodu.Text.Delimited 1.3.0
Source
DelimitedReaderOptions.cs

Provides configuration for a Utf8DelimitedReader, controlling the delimiter, quoting, header handling, and the field-count and duplicate-header policies.

public readonly struct DelimitedReaderOptions
Inherited Members
Extension Methods

Remarks

The options are an immutable value type. Because the default value of a char is '\0', the delimiter and quote fall back to their RFC 4180 defaults (',' and '"'), and the comment character to '#', a Bodu default since RFC 4180 defines no comments, when left unset, and headers are read by default (set NoHeader to disable).

The reader matches the delimiter, quote, and comment characters as single bytes of the UTF-8 input, so each must be an ASCII character other than a carriage return or a line feed, and no two of them may be the same character. The comment character must differ from the delimiter and the quote even when AllowComments is not set. The Utf8DelimitedReader constructor throws ArgumentException for options that break these rules.

Properties

AllowComments

Gets a value indicating whether lines beginning with the comment character are skipped.

public bool AllowComments { get; init; }

Property Value

bool

true to allow comment lines; otherwise false.

CommentChar

Gets the comment character, or '\0' to use the default '#'.

public char CommentChar { get; init; }

Property Value

char

The comment character.

Remarks

The comment character must be an ASCII character other than a carriage return or a line feed, and must differ from Delimiter and Quote, even when AllowComments is not set.

Default

Gets the default reader options (comma delimiter, double-quote quoting, header row present).

public static DelimitedReaderOptions Default { get; }

Property Value

DelimitedReaderOptions

The default options.

Delimiter

Gets the field delimiter, or '\0' to use the default comma.

public char Delimiter { get; init; }

Property Value

char

The delimiter character.

Remarks

The delimiter must be an ASCII character other than a carriage return or a line feed, and must differ from Quote and CommentChar.

DuplicateHeaderBehavior

Gets the policy applied to a header row that repeats a column name.

public DelimitedDuplicateHeaderBehavior DuplicateHeaderBehavior { get; init; }

Property Value

DelimitedDuplicateHeaderBehavior

The duplicate-header behavior.

FieldCountBehavior

Gets the policy applied to a record whose field count differs from the header's.

public DelimitedFieldCountBehavior FieldCountBehavior { get; init; }

Property Value

DelimitedFieldCountBehavior

The field-count behavior.

MalformedRecordBehavior

Gets the policy applied to a malformed record: one that violates the field-count policy, or one in which text follows a closing quote.

public DelimitedMalformedRecordBehavior MalformedRecordBehavior { get; init; }

Property Value

DelimitedMalformedRecordBehavior

The malformed-record behavior.

NoHeader

Gets a value indicating whether the first record is treated as data rather than a header row.

public bool NoHeader { get; init; }

Property Value

bool

true when there is no header; otherwise false.

Quote

Gets the quote character, or '\0' to use the default double quote.

public char Quote { get; init; }

Property Value

char

The quote character.

Remarks

The quote must be an ASCII character other than a carriage return or a line feed, and must differ from Delimiter and CommentChar.

TrimFields

Gets a value indicating whether spaces and tabs around each field are trimmed.

public bool TrimFields { get; init; }

Property Value

bool

true to trim fields; otherwise false.

Remarks

An unquoted field loses its leading and trailing spaces and tabs. Spaces and tabs before a quoted field's opening quote and after its closing quote are skipped, so the field is still read as quoted, and the text between its quotes is never trimmed. Without this option a field that begins with a space is unquoted, and any quotes in it are literal text.

Only U+0020 (space) and U+0009 (tab) are trimmed: other white space, such as U+00A0 (no-break space), U+3000 (ideographic space) or U+000B (vertical tab), stays in the value. A delimiter or quote character that is a space or a tab is never trimmed.

Applies to

ProductVersions
.NET8, 10