Namespace
CsvHelper
Assembly
CsvHelper.dll
Inheritance
object Attribute CsvColumnAttribute
Builds
net10.0 netstandard2.1 netstandard2.0 net47

Constructors

CsvColumnAttribute(string)

Added in v34.0.0
public CsvColumnAttribute(string name)

Reads the header column called name.

Parameters

namestring
The header name of the column. It is matched like the other names: exactly first, then ignoring case and surrounding whitespace.

View source

public CsvColumnAttribute(string name, params string[] alternateNames)

Reads the header column called name, or else the first of alternateNames that the header has, for files whose header changed between versions.

Parameters

namestring
The header name of the column, tried first.
alternateNamesstring[]
Other names of the column, tried in order when the header lacks name.

View source

Properties

AlternateNames

Added in v34.0.0
public IReadOnlyList<string> AlternateNames { get; }

Other header names of the column, tried in order when the header lacks Name. Each name is matched exactly first, then ignoring case and surrounding whitespace, before the next one is tried.

Property value

View source

EndIndex

Added in v34.0.0
public int EndIndex { get; set; }

For a collection member (an array, List<T>, IEnumerable<T>, IList<T>, IReadOnlyList<T> and the like, or a dictionary with string keys) with an Index: the 0-based index of its last column, so that it reads the fields from Index to EndIndex. -1 (the default) reads to the last field of each record (for a dictionary, to the last column of the header). A collection member without an index reads every header column with its name instead.

Property value

int

View source

Index

Added in v34.0.0
public int Index { get; set; }

The 0-based index of the column, used instead of the header; needed when the input has no header. -1 (the default) finds the column by name. For a collection member, the first of its columns (see EndIndex).

Property value

int

View source

Name

Added in v34.0.0
public string? Name { get; }

The header name of the column, or null for the member's name.

Property value

string?

View source

NameIndex

Added in v34.0.0
public int NameIndex { get; set; }

Which of several header columns with the same name the member reads: 0 (the default) for the first, 1 for the second, and so on. The record writer writes the columns with the same name in this order.

Property value

int

View source

Optional

Added in v34.0.0
public bool Optional { get; set; }

Whether the column may be missing from the header. A missing optional member keeps its default value; a missing required one makes CsvReader.GetRecords throw. Constructor parameters with a default value are always optional.

Property value

bool

View source

Prefix

Added in v34.0.0
public string? Prefix { get; set; }

For a member whose type is itself a record type (a CsvRecordAttribute type, or a type with a CsvConverterAttribute): the text put in front of each header name that the member's type looks up, such as "Ship " for the columns Ship Street and Ship City. The prefixes of records nested in nested records add up. null (the default) adds nothing.

Property value

string?

View source