FastCsvReader
Provides fast CSV reading capabilities from various input sources.
Inherits: Disposable
Constructors
public FastCsvReader(Stream stream, Encoding encoding, string lineSeparator)
fastCsvReader = FastCsvReader(stream, encoding, lineSeparator)
Initializes a new instance of the FastCsvReader class using a stream, encoding, and line separator.
- stream
- The input stream to read CSV data from.
- encoding
- The character encoding to use.
- lineSeparator
- The string that separates lines.
public FastCsvReader(TextReader reader, string lineSeparator, bool leaveOpen)
fastCsvReader = FastCsvReader(reader, lineSeparator, leaveOpen)
Initializes a new instance of the FastCsvReader class using a TextReader and line separator.
- reader
- The TextReader to read CSV data from.
- lineSeparator
- The string that separates lines.
- leaveOpen
- Specifies whether the reader should remain open after the FastCsvReader is disposed.
public FastCsvReader(TextReader reader, string lineSeparator)
fastCsvReader = FastCsvReader(reader, lineSeparator)
Initializes a new instance of the FastCsvReader class using a TextReader and line separator.
- reader
- The TextReader to read CSV data from.
- lineSeparator
- The string that separates lines.
public FastCsvReader(string content, string lineSeparator)
fastCsvReader = FastCsvReader(content, lineSeparator)
Initializes a new instance of the FastCsvReader class using a string content and line separator.
- content
- The string content to read CSV data from.
- lineSeparator
- The string that separates lines.
public FastCsvReader(Stream stream, Encoding encoding, string lineSeparator, bool leaveOpen)
fastCsvReader = FastCsvReader(stream, encoding, lineSeparator, leaveOpen)
Initializes a new instance of the FastCsvReader class using a stream, encoding, and line separator.
- stream
- The input stream to read CSV data from.
- encoding
- The character encoding to use.
- lineSeparator
- The string that separates lines.
- leaveOpen
- Specifies whether the stream should remain open after the FastCsvReader is disposed.
Properties
public int ColumnCount { get; }
value = fastCsvReader.ColumnCount
Gets the number of columns in the current CSV line.
public int ColumnCurr { get; }
value = fastCsvReader.ColumnCurr
Gets the current column index being processed.
public char ColumnSeparator { get; set; }
value = fastCsvReader.ColumnSeparator
fastCsvReader.ColumnSeparator = value
Gets or sets the character used to separate columns.
public string CurrentLine { get; }
value = fastCsvReader.CurrentLine
Gets the current CSV line as a string.
public TextReader Reader { get; }
value = fastCsvReader.Reader
Gets the underlying text reader.
Methods
protected override void DisposeManaged()
fastCsvReader.DisposeManaged()
Disposes the managed resources. Override this method to add custom clean up of managed resources.
public ValueTask<bool> NextLineAsync(CancellationToken cancellationToken)
result = fastCsvReader.NextLineAsync(cancellationToken)
Asynchronously reads the next CSV line from the underlying stream or reader.
- cancellationToken
- Cancellation token.
Returns: true if a new line was successfully read; otherwise, false.
public bool ReadBool()
result = fastCsvReader.ReadBool()
Reads the next column as a boolean value.
Returns: The boolean value read from the column.
public DateTime ReadDateTime(string format)
result = fastCsvReader.ReadDateTime(format)
Reads the next column as a DateTime value using the specified format.
- format
- The date and time format string.
Returns: The DateTime value read from the column.
public decimal ReadDecimal()
result = fastCsvReader.ReadDecimal()
Reads the next column as a decimal value.
Returns: The decimal value read from the column.
public double ReadDouble()
result = fastCsvReader.ReadDouble()
Reads the next column as a double value.
Returns: The double value read from the column.
public T ReadEnum<T>()
result = fastCsvReader.ReadEnum()
Reads the next column as an enum value of type .
Returns: The enum value read from the column.
public int ReadInt()
result = fastCsvReader.ReadInt()
Reads the next column as an integer value.
Returns: The integer value read from the column.
public long ReadLong()
result = fastCsvReader.ReadLong()
Reads the next column as a long value.
Returns: The long value read from the column.
public bool? ReadNullableBool()
result = fastCsvReader.ReadNullableBool()
Reads the next column as a nullable boolean value.
Returns: A nullable boolean value read from the column, or null if the column is empty.
public DateTime? ReadNullableDateTime(string format)
result = fastCsvReader.ReadNullableDateTime(format)
Reads the next column as a nullable DateTime value using the specified format.
- format
- The date and time format string.
Returns: A nullable DateTime value read from the column, or null if the column is empty.
public decimal? ReadNullableDecimal()
result = fastCsvReader.ReadNullableDecimal()
Reads the next column as a nullable decimal value.
Returns: A nullable decimal value read from the column, or null if the column is empty.
public double? ReadNullableDouble()
result = fastCsvReader.ReadNullableDouble()
Reads the next column as a nullable double value.
Returns: A nullable double value read from the column, or null if the column is empty.
public T? ReadNullableEnum<T>()
result = fastCsvReader.ReadNullableEnum()
Reads the next column as a nullable enum value of type .
Returns: A nullable enum value read from the column, or null if the column is empty.
public int? ReadNullableInt()
result = fastCsvReader.ReadNullableInt()
Reads the next column as a nullable integer value.
Returns: A nullable integer value read from the column, or null if the column is empty.
public long? ReadNullableLong()
result = fastCsvReader.ReadNullableLong()
Reads the next column as a nullable long value.
Returns: A nullable long value read from the column, or null if the column is empty.
public TimeSpan? ReadNullableTimeSpan(string format)
result = fastCsvReader.ReadNullableTimeSpan(format)
Reads the next column as a nullable TimeSpan value using the specified format.
- format
- The time span format string.
Returns: A nullable TimeSpan value read from the column, or null if the column is empty.
public string ReadString()
result = fastCsvReader.ReadString()
Reads the next column as a string.
Returns: The string read from the column, or null if the column is empty.
public TimeSpan ReadTimeSpan(string format)
result = fastCsvReader.ReadTimeSpan(format)
Reads the next column as a TimeSpan value using the specified format.
- format
- The time span format string.
Returns: The TimeSpan value read from the column.
public void Skip(int count)
fastCsvReader.Skip(count)
Skips the specified number of columns.
- count
- The number of columns to skip. Defaults to 1.