Table of Contents

Class CsvRecordEnumerator<T>

Namespace
FlameCsv.Enumeration
Assembly
FlameCsv.Core.dll

An enumerator that parses CSV records.

public sealed class CsvRecordEnumerator<T> : CsvEnumeratorBase<T>, IEnumerator<CsvValueRecord<T>>, IEnumerator, IDisposable, IAsyncEnumerator<CsvValueRecord<T>>, IAsyncDisposable where T : unmanaged, IBinaryInteger<T>

Type Parameters

T
Inheritance
CsvRecordEnumerator<T>
Implements
Inherited Members

Remarks

If the options are configured to read a header record, it will be processed first before any records are yielded.
This class is not thread-safe, and should not be used concurrently.
The enumerator should always be disposed after use, either explicitly or using foreach.

Constructors

CsvRecordEnumerator(CsvOptions<T>, ICsvPipeReader<T>, CancellationToken)

Initializes a new instance of CsvRecordEnumerator<T>.

public CsvRecordEnumerator(CsvOptions<T> options, ICsvPipeReader<T> reader, CancellationToken cancellationToken = default)

Parameters

options CsvOptions<T>

Options-instance

reader ICsvPipeReader<T>

Reader for the CSV data

cancellationToken CancellationToken

Cancellation token used for asynchronous enumeration

Properties

Current

Gets the current record.

public ref readonly CsvValueRecord<T> Current { get; }

Property Value

CsvValueRecord<T>

Remarks

The value should not be held onto after the enumeration continues or ends, as the records wrap shared and/or pooled memory. If you must, convert the record to CsvRecord<T>.

Exceptions

ObjectDisposedException

Thrown when the enumerator has been disposed.

InvalidOperationException

Thrown when enumeration has not yet started.

Header

Current header value. May be null if a header is not yet read, header is reset, or if the CSV has no header.

public CsvHeader? Header { get; set; }

Property Value

CsvHeader

Exceptions

ObjectDisposedException
NotSupportedException

Thrown when the CSV has no header and a non-null value is set.

Methods

Dispose(bool)

When overridden, disposes the underlying data source and internal states.

protected override void Dispose(bool disposing)

Parameters

disposing bool

Remarks

The default implementation does nothing. Override both this and DisposeAsyncCore()

DisposeAsyncCore()

Disposes resources for inheriting classes.

protected override ValueTask DisposeAsyncCore()

Returns

ValueTask

Remarks

The default implementation does nothing. Override both this and Dispose(bool)

GetHeader()

Returns the header record's fields, or empty if none is read.

protected override ReadOnlySpan<string> GetHeader()

Returns

ReadOnlySpan<string>

MoveNextCore(ref readonly CsvFields<T>)

Attempts to read the next CSV record from the inner parser.

protected override bool MoveNextCore(ref readonly CsvFields<T> fields)

Parameters

fields CsvFields<T>

Current CSV record

Returns

bool

true if the enumerator produced the next value, false if the record was a header record, or was skipped.

Remarks

When this method is called, Position points to the start of the record.

ResetHeader()

Resets the header. No-op if the header is not read.

protected override void ResetHeader()