Class FastCsvReader
Provides fast CSV reading capabilities from various input sources.
public class FastCsvReader
- Inheritance
-
FastCsvReader
- Inherited Members
- Extension Methods
Constructors
FastCsvReader(Stream, Encoding, string)
Initializes a new instance of the FastCsvReader class using a stream, encoding, and line separator.
public FastCsvReader(Stream stream, Encoding encoding, string lineSeparator)
Parameters
stream
StreamThe input stream to read CSV data from.
encoding
EncodingThe character encoding to use.
lineSeparator
stringThe string that separates lines.
FastCsvReader(TextReader, string)
Initializes a new instance of the FastCsvReader class using a TextReader and line separator.
public FastCsvReader(TextReader reader, string lineSeparator)
Parameters
reader
TextReaderThe TextReader to read CSV data from.
lineSeparator
stringThe string that separates lines.
FastCsvReader(string, string)
Initializes a new instance of the FastCsvReader class using a string content and line separator.
public FastCsvReader(string content, string lineSeparator)
Parameters
content
stringThe string content to read CSV data from.
lineSeparator
stringThe string that separates lines.
Properties
ColumnCount
Gets the number of columns in the current CSV line.
public int ColumnCount { get; }
Property Value
ColumnCurr
Gets the current column index being processed.
public int ColumnCurr { get; }
Property Value
ColumnSeparator
Gets or sets the character used to separate columns.
public char ColumnSeparator { get; set; }
Property Value
CurrentLine
Gets the current CSV line as a string.
public string CurrentLine { get; }
Property Value
Reader
Gets the underlying text reader.
public TextReader Reader { get; }
Property Value
Methods
NextLine()
Reads the next CSV line from the underlying stream or reader.
public bool NextLine()
Returns
- bool
true
if a new line was successfully read; otherwise,false
.
ReadBool()
Reads the next column as a boolean value.
public bool ReadBool()
Returns
- bool
The boolean value read from the column.
ReadDateTime(string)
Reads the next column as a DateTime value using the specified format.
public DateTime ReadDateTime(string format)
Parameters
format
stringThe date and time format string.
Returns
- DateTime
The DateTime value read from the column.
ReadDecimal()
Reads the next column as a decimal value.
public decimal ReadDecimal()
Returns
- decimal
The decimal value read from the column.
ReadDouble()
Reads the next column as a double value.
public double ReadDouble()
Returns
- double
The double value read from the column.
ReadEnum<T>()
Reads the next column as an enum value of type T
.
public T ReadEnum<T>() where T : struct
Returns
- T
The enum value read from the column.
Type Parameters
T
The enum type to convert to.
ReadInt()
Reads the next column as an integer value.
public int ReadInt()
Returns
- int
The integer value read from the column.
ReadLong()
Reads the next column as a long value.
public long ReadLong()
Returns
- long
The long value read from the column.
ReadNullableBool()
Reads the next column as a nullable boolean value.
public bool? ReadNullableBool()
Returns
- bool?
A nullable boolean value read from the column, or null if the column is empty.
ReadNullableDateTime(string)
Reads the next column as a nullable DateTime value using the specified format.
public DateTime? ReadNullableDateTime(string format)
Parameters
format
stringThe date and time format string.
Returns
- DateTime?
A nullable DateTime value read from the column, or null if the column is empty.
ReadNullableDecimal()
Reads the next column as a nullable decimal value.
public decimal? ReadNullableDecimal()
Returns
- decimal?
A nullable decimal value read from the column, or null if the column is empty.
ReadNullableDouble()
Reads the next column as a nullable double value.
public double? ReadNullableDouble()
Returns
- double?
A nullable double value read from the column, or null if the column is empty.
ReadNullableEnum<T>()
Reads the next column as a nullable enum value of type T
.
public T? ReadNullableEnum<T>() where T : struct
Returns
- T?
A nullable enum value read from the column, or null if the column is empty.
Type Parameters
T
The enum type to convert to.
ReadNullableInt()
Reads the next column as a nullable integer value.
public int? ReadNullableInt()
Returns
- int?
A nullable integer value read from the column, or null if the column is empty.
ReadNullableLong()
Reads the next column as a nullable long value.
public long? ReadNullableLong()
Returns
- long?
A nullable long value read from the column, or null if the column is empty.
ReadNullableTimeSpan(string)
Reads the next column as a nullable TimeSpan value using the specified format.
public TimeSpan? ReadNullableTimeSpan(string format)
Parameters
format
stringThe time span format string.
Returns
- TimeSpan?
A nullable TimeSpan value read from the column, or null if the column is empty.
ReadString()
Reads the next column as a string.
public string ReadString()
Returns
- string
The string read from the column, or null if the column is empty.
ReadTimeSpan(string)
Reads the next column as a TimeSpan value using the specified format.
public TimeSpan ReadTimeSpan(string format)
Parameters
format
stringThe time span format string.
Returns
- TimeSpan
The TimeSpan value read from the column.
Skip(int)
Skips the specified number of columns.
public void Skip(int count = 1)
Parameters
count
intThe number of columns to skip. Defaults to 1.
Exceptions
- ArgumentOutOfRangeException
Thrown if the count is less than or equal to 0.
- ArgumentException
Thrown if skipping the specified columns would exceed the number of columns available in the current line.