CsvWriterOptions Class

Options that control how CsvWriter and Utf8CsvWriter write CSV data.

public sealed class CsvWriterOptions : IEquatable<CsvWriterOptions>

Remarks

The options are immutable. Use a with expression to create a copy with other values.

Implements

Constructors

NameDescription
CsvWriterOptions()

CsvWriterOptions()

CsvWriterOptions.cs
public CsvWriterOptions()

No documentation is available.

Properties

NameDescription
BufferSizeGets the size, in characters or in bytes, of the buffer of the writer. Default is 16384.
DefaultGets the default options: comma separator, double quote, \r\n line terminator, values quoted as needed.
EscapeFormulasGets a value indicating whether text values that a spreadsheet would run as a formula are escaped. Default is false.
FormatProviderGets the format provider used to format values. Default is null, which means CultureInfo.InvariantCulture.
NewLineGets the string written at the end of each row. Default is \r\n, as in RFC 4180.
QuoteGets the character that quotes values. Default is ". When null, values are never quoted.
QuoteModeGets when values are quoted. Default is CsvQuoteMode.AsNeeded.
SeparatorGets the character that separates the values of a row. Default is ,.

Gets the size, in characters or in bytes, of the buffer of the writer. Default is 16384.

public int BufferSize { get; init; }

Property value

int

Remarks

The writer sends its buffer to the underlying writer, stream or buffer writer when it is mostly full at the end of a row, and when it is flushed.

Gets the default options: comma separator, double quote, \r\n line terminator, values quoted as needed.

public static CsvWriterOptions Default { get; }

Property value

CsvWriterOptions

EscapeFormulas

CsvWriterOptions.cs

Gets a value indicating whether text values that a spreadsheet would run as a formula are escaped. Default is false.

public bool EscapeFormulas { get; init; }

Property value

bool

Remarks

When true, a text value that starts with =, +, -, @, a tab or a carriage return is prefixed with a single quote, which prevents CSV injection when the file is opened in a spreadsheet. Values written from numbers and other formattable values are not escaped. When CsvWriterOptions.Quote is a single quote, an escaped value is always quoted and its prefix is doubled, so that it reads back with the prefix.

FormatProvider

CsvWriterOptions.cs

Gets the format provider used to format values. Default is null, which means CultureInfo.InvariantCulture.

public IFormatProvider? FormatProvider { get; init; }

Property value

IFormatProvider?

Gets the string written at the end of each row. Default is \r\n, as in RFC 4180.

public string NewLine { get; init; }

Property value

string

Gets the character that quotes values. Default is ". When null, values are never quoted.

public char? Quote { get; init; }

Property value

char?

Remarks

Utf8CsvWriter requires an ASCII quote character.

Gets when values are quoted. Default is CsvQuoteMode.AsNeeded.

public CsvQuoteMode QuoteMode { get; init; }

Property value

CsvQuoteMode

Gets the character that separates the values of a row. Default is ,.

public char Separator { get; init; }

Property value

char

Remarks

Utf8CsvWriter requires an ASCII separator.

Methods

NameDescription
Equals(CsvWriterOptions?)
Equals(object?)
GetHashCode()
ToString()

Equals overloads

Equals(CsvWriterOptions?)

public bool Equals(CsvWriterOptions? other)
Parameters
other CsvWriterOptions?
Returns

bool

No documentation is available.

Equals(object?)

public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

public override int GetHashCode()

Returns

int

No documentation is available.

ToString()

public override string ToString()

Returns

string

No documentation is available.

Operators

NameDescription
operator ==(CsvWriterOptions?, CsvWriterOptions?)
operator !=(CsvWriterOptions?, CsvWriterOptions?)

operator ==(CsvWriterOptions?, CsvWriterOptions?)

public static bool operator ==(CsvWriterOptions? left, CsvWriterOptions? right)

Parameters

left CsvWriterOptions?
right CsvWriterOptions?

Returns

bool

No documentation is available.

operator !=(CsvWriterOptions?, CsvWriterOptions?)

public static bool operator !=(CsvWriterOptions? left, CsvWriterOptions? right)

Parameters

left CsvWriterOptions?
right CsvWriterOptions?

Returns

bool

No documentation is available.