CsvWriterOptions()
public CsvWriterOptions()Initializes a new instance of CsvWriterOptions.
Record in CsvHelper
public sealed record CsvWriterOptionsCsvHelperCsvHelper.dllpublic CsvWriterOptions()Initializes a new instance of CsvWriterOptions.
public int BufferSize { get; init; }The size in bytes of the write buffer. Defaults to 64 KiB.
public char? CommentPrefix { get; init; }The character that starts the comment lines that CsvWriter.WriteComment(string) writes, such as #. Defaults to null: no comments. When it is set, a record whose first field starts with it has that field quoted (CsvMode.Rfc4180) or escaped (CsvMode.Escape), so that a reader with the same CsvReaderOptions.CommentPrefix does not skip the record; such a record throws InvalidOperationException in CsvMode.FixedWidth mode and is written as it is in CsvMode.NoEscape mode. Must be an ASCII character other than the separator, the quote (in CsvMode.Rfc4180 mode) and Escape (in CsvMode.Escape mode).
public static CsvWriterOptions Default { get; }The default options: RFC 4180, comma separated, quote when needed, consistent field counts.
public char Escape { get; init; }The escape character of CsvMode.Escape mode. Defaults to \. Must be an ASCII character other than space, tab and the separator.
public string FalseValue { get; init; }The text written for false. Defaults to False.
public IReadOnlyList<int>? FieldWidths { get; init; }The widths of the columns in CsvMode.FixedWidth mode, in characters (UTF-16 code units, as string.Length counts them). Required in that mode; every width must be positive.
public IFormatProvider FormatProvider { get; init; }The format provider for numbers and dates. Defaults to CultureInfo.InvariantCulture.
public bool HasHeader { get; init; }Whether CsvWriter.WriteRecords<T>(IEnumerable<T>) and the other methods that write a sequence of records start the output with the header of the record type. Defaults to true. CsvWriter.WriteHeader<T>() writes a header either way.
public CsvInjection Injection { get; init; }What to do with text fields that start with one of InjectionCharacters, which a spreadsheet would run as a formula. Defaults to CsvInjection.None. It applies to text (strings, character and UTF-8 spans, and values written with object.ToString), not to numbers, dates, times, Guids and booleans, so -5 stays a number.
public string InjectionCharacters { get; init; }The characters that make a text field a possible formula when it starts with one of them. Defaults to = @ + -, tab and CR, as OWASP recommends. Must be ASCII.
public char InjectionEscape { get; init; }The character that CsvInjection.Escape puts in front of a possible formula. Defaults to ', which Excel reads as "this cell is text". Must be an ASCII character other than CR, LF, the separator and the InjectionCharacters.
public CsvMode Mode { get; init; }How fields are delimited and escaped. Records end with NewLine in every mode.
public string NewLine { get; init; }The line ending written after each record and comment: "\r\n" (the default, which RFC 4180 specifies), "\n" or "\r". Fields that contain CR or LF are still quoted or escaped whichever is chosen. In CsvMode.Escape mode with "\n", a record whose last value ends with a CR ends with CRLF, because a reader takes an LF right after an escaped CR as part of the value.
public string? NullValue { get; init; }The text written for null: a null string, object or Nullable<T>, such as NULL or \N for a database import. Defaults to null: an empty field. Character and UTF-8 spans cannot be null, so an empty span is an empty field whatever this is. A reader with the same value in CsvReaderOptions.NullValues reads it back as null.
public CsvQuoting Quoting { get; init; }When fields are quoted in CsvMode.Rfc4180 mode. Defaults to CsvQuoting.WhenNeeded.
public char Separator { get; init; }The field separator. RFC 4180 specifies a comma (the default). Another ASCII separator can be used (for example ; or tab); quoting still follows the RFC rules for that separator. Not used in CsvMode.FixedWidth mode.
public CsvShouldQuote? ShouldQuote { get; init; }Called for each field in CsvMode.Rfc4180 mode to decide whether to quote a field that does not need quotes, such as text fields but not numbers. A field that contains the separator, a quote, CR or LF is always quoted, and with CsvQuoting.Always every field is. Defaults to null. Writing is slower with a callback, which gets the text of every field. The parallel writes of CsvWriter call it on several threads at once.
public string TrueValue { get; init; }The text written for true. Defaults to True.
public bool ValidateFieldCount { get; init; }Whether every record must have the same number of fields as the first one, as RFC 4180 requires (in CsvMode.FixedWidth mode, a field for every column). Defaults to true; a mismatch throws InvalidOperationException.
public bool WriteByteOrderMark { get; init; }Whether to start the output with a UTF-8 byte order mark. Defaults to false.
public static CsvWriterOptions For<T>()The options for the files of T: the defaults with the settings of the type's CsvOptionsAttribute, or Default when it has none. Change the rest with a with expression, such as CsvWriterOptions.For<Order>() with { Quoting = CsvQuoting.Always }.
T