Class CsvReader
A class for reading comma-separated values data from a stream.
public class CsvReader
- Inheritance
-
CsvReader
- Inherited Members
Constructors
CsvReader(TextReader)
Initializes a new instance of the CsvReader class.
public CsvReader(TextReader reader)
Parameters
reader
TextReaderThe reader from which to read the CSV data.
Properties
LineNumber
Gets the line number of the next character waiting to be read.
public int LineNumber { get; }
Property Value
Methods
GetNextRow()
Retrieve the next CSV row from the data stream.
public string[] GetNextRow()
Returns
- string[]
An array containing the CSV columns, or null if there are no more rows in the input stream.
Read<T>(string, ICollection<T>, bool)
Reads a comma-separated file into a collection of strongly-typed objects.
public static void Read<T>(string path, ICollection<T> collection, bool isFirstRowHeader)
Parameters
path
stringThe path to the CSV file.
collection
ICollection<T>The collection into which objects read from the CSV file will be added.
isFirstRowHeader
boolWhether the first line in the CSV file should be treated as a header line.
Type Parameters
T
The strongly-typed object type.
Remarks
The strongly-typed object class should contain public properties decorated with the CsvColumnAttribute attribute, mapping them to columns in the CSV file.