Click or drag to resize

CsvTableReader Class

Used to read a CSV table that includes row headers.
Inheritance Hierarchy
SystemObject
  Neon.CsvCsvTableReader

Namespace:  Neon.Csv
Assembly:  Neon.Common (in Neon.Common.dll) Version: 2.1.0
Syntax
public class CsvTableReader : IDisposable

The CsvTableReader type exposes the following members.

Constructors
  NameDescription
Public methodCsvTableReader(TextReader)
Constructs an instance to read from a TextReader.
Public methodCsvTableReader(String)
Constructs an instance to read from a CSV string.
Public methodCsvTableReader(CsvReader)
Constructs an instance to read from a CsvReader.
Public methodCsvTableReader(Stream, Encoding)
Constructs an instance to read from a stream.
Top
Properties
  NameDescription
Public propertyColumnMap
Returns the dictionary that case insensitvely maps a column name to the zero based index of the column.
Public propertyColumns
Returns the list of table columns in the order read from the source.
Public propertyItemInt32
Indexer that returns the value for a column.
Public propertyItemString
Indexer that returns the value for the named column in the current row.
Public propertyReader
Returns the underlying CsvReader or null if the reader is closed.
Top
Methods
  NameDescription
Public methodClose
Closes the reader if it is still open.
Public methodDispose
Releases any system resources held by the instance,
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetColumn
Returns the value for the named column in the current row.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsEmpty
Determines whether a cell in a named column in the current row is empty or if the column does not exist.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodReadRow
Reads the next row of table.
Public methodRows
Returns an enumerator that returns the data rows from a CsvTableReader.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

This class makes it easy to process tabular data loaded from a CSV file, where the first row of the file contains the row header strings that identify the table columns.

Initialize an instance by passing a CsvReader, stream, string, or file path to the constructor. The constructor will read the first row of the file and initialize the ColumnMap dictionary which maps the case insensitive column name to the zero based index of the column in the table.

You'll process each data row by calling ReadRow. This returns a list with the next row of data or null if the end of the table has been reached. You can process the row data returned directly or use the GetColumn(String) method to access a column value on the current row directly.

Note Note
This class is tolerant of blank or duplicate column names. In the case of duplicates, the first column matching the requested column name will be used when parsing data.

Applications should call the reader's Dispose or Close method when they are finished with the reader so that the underlying CsvReader will be closed as well, promptly releasing any system resources (such as the stream).

See Also