Table of Contents

Class CsvFile

Namespace
SunamoCsv
Assembly
SunamoCsv.dll
public sealed class CsvFile
Inheritance
CsvFile
Inherited Members
Extension Methods

Constructors

CsvFile()

Initializes a new instance of the CsvFile class

public CsvFile()

CsvFile(char)

Initializes a new instance of the CsvFile class with specified delimiter

public CsvFile(char delimiter)

Parameters

delimiter char

Character to use as field delimiter

Fields

Headers

Gets the file headers

public readonly List<string> Headers

Field Value

List<string>

Records

Gets the records in the file

public readonly CsvRecords Records

Field Value

CsvRecords

Properties

HeaderCount

Gets the header count

public int HeaderCount { get; }

Property Value

int

this[int]

Gets a record at the specified index

public CsvRecord this[int recordIndex] { get; }

Parameters

recordIndex int

Record index

Property Value

CsvRecord

CsvRecord

this[int, int]

Gets the field value at the specified record and field index

public string this[int recordIndex, int fieldIndex] { get; set; }

Parameters

recordIndex int

Record index

fieldIndex int

Field index

Property Value

string

this[int, string]

Gets the field value at the specified record index for the supplied field name

public string this[int recordIndex, string fieldName] { get; set; }

Parameters

recordIndex int

Record index

fieldName string

Field name

Property Value

string

RecordCount

Gets the record count

public int RecordCount { get; }

Property Value

int

Methods

DateTimes(int)

Return null when cannot be parsed

public List<DateTime?> DateTimes(int columnIndex)

Parameters

columnIndex int

Returns

List<DateTime?>

Objects(params int[])

Returns values from specified columns as list of lists

public List<List<string>> Objects(params int[] columns)

Parameters

columns int[]

Array of zero-based column indices

Returns

List<List<string>>

List of lists containing values from specified columns

Populate(bool, string)

Populates the current instance from a string

public void Populate(bool hasHeaderRow, string csvContent)

Parameters

hasHeaderRow bool

True if the file has a header row, otherwise false

csvContent string

Csv text

Populate(bool, string, bool)

Populates the current instance from a string

public void Populate(bool hasHeaderRow, string csvContent, bool isTrimmingColumns)

Parameters

hasHeaderRow bool

True if the file has a header row, otherwise false

csvContent string

Csv text

isTrimmingColumns bool

True if column values should be trimmed, otherwise false

Populate(bool, string, Encoding?, bool)

Populates the current instance from a string

public void Populate(bool hasHeaderRow, string csvContent, Encoding? encoding, bool isTrimmingColumns)

Parameters

hasHeaderRow bool

True if the file has a header row, otherwise false

csvContent string

Csv text

encoding Encoding

Encoding (null for UTF8)

isTrimmingColumns bool

True if column values should be trimmed, otherwise false

Populate(Stream, bool)

Populates the current instance from a stream

public void Populate(Stream stream, bool hasHeaderRow)

Parameters

stream Stream

Stream

hasHeaderRow bool

True if the file has a header row, otherwise false

Populate(Stream, bool, bool)

Populates the current instance from a stream

public void Populate(Stream stream, bool hasHeaderRow, bool isTrimmingColumns)

Parameters

stream Stream

Stream

hasHeaderRow bool

True if the file has a header row, otherwise false

isTrimmingColumns bool

True if column values should be trimmed, otherwise false

Populate(Stream, Encoding?, bool, bool)

Populates the current instance from a stream

public void Populate(Stream stream, Encoding? encoding, bool hasHeaderRow, bool isTrimmingColumns)

Parameters

stream Stream

Stream

encoding Encoding

Encoding (null for UTF8)

hasHeaderRow bool

True if the file has a header row, otherwise false

isTrimmingColumns bool

True if column values should be trimmed, otherwise false

Populate(string, bool)

Populates the current instance from the specified file

public void Populate(string filePath, bool hasHeaderRow)

Parameters

filePath string

File path

hasHeaderRow bool

True if the file has a header row, otherwise false

Populate(string, bool, bool)

Populates the current instance from the specified file

public void Populate(string filePath, bool hasHeaderRow, bool isTrimmingColumns)

Parameters

filePath string

File path

hasHeaderRow bool

True if the file has a header row, otherwise false

isTrimmingColumns bool

True if column values should be trimmed, otherwise false

Populate(string, Encoding?, bool, bool)

Populates the current instance from the specified file

public void Populate(string filePath, Encoding? encoding, bool hasHeaderRow, bool isTrimmingColumns)

Parameters

filePath string

File path

encoding Encoding

Encoding (null for UTF8)

hasHeaderRow bool

True if the file has a header row, otherwise false

isTrimmingColumns bool

True if column values should be trimmed, otherwise false

Strings(int)

Returns string values from specified column

public List<string> Strings(int columnIndex)

Parameters

columnIndex int

Zero-based column index

Returns

List<string>

List of string values from the column