CsvColumnAttribute()
public CsvColumnAttribute()Attribute in CsvHelper
Chooses the column of a member or constructor parameter of a CsvRecordAttribute type.
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class CsvColumnAttribute : AttributeCsvHelperCsvHelper.dllpublic CsvColumnAttribute()public CsvColumnAttribute(string name)Reads the header column called name.
namestringpublic 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.
namestringalternateNamesstring[]name.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.
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.
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).
public string? Name { get; }The header name of the column, or null for the member's name.
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.
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.
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.
public int Width { get; set; }The width of the column in CsvMode.FixedWidth files, in characters (UTF-16 code units, as string.Length counts them), or 0 (the default) for none. A member with a width needs an Index: the widths of a type's members, ordered by their indexes, are its layout, which CsvRecordMapper.GetFieldWidths returns for CsvReaderOptions.FieldWidths.