Class CsvRecordEnumerator<T>
- Namespace
- FlameCsv.Enumeration
- Assembly
- FlameCsv.Core.dll
An enumerator that parses CSV records.
public sealed class CsvRecordEnumerator<T> : CsvEnumeratorBase<T>, IEnumerator<CsvRecord<T>>, IEnumerator, IAsyncEnumerator<CsvRecord<T>>, IAsyncDisposable, IDataReader, IDataRecord, IDisposable where T : unmanaged, IBinaryInteger<T>
Type Parameters
T
- Inheritance
-
objectCsvRecordEnumerator<T>
- Implements
-
IEnumerator<CsvRecord<T>>
- 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>, ICsvBufferReader<T>, CancellationToken)
Initializes a new instance of CsvRecordEnumerator<T>.
public CsvRecordEnumerator(CsvOptions<T> options, ICsvBufferReader<T> reader, CancellationToken cancellationToken = default)
Parameters
options
CsvOptions<T>Options-instance
reader
ICsvBufferReader<T>Reader for the CSV data
cancellationToken
CancellationTokenCancellation token used for asynchronous enumeration
Properties
Current
Gets the current record.
public ref readonly CsvRecord<T> Current { get; }
Property Value
- CsvRecord<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 CsvPreservedRecord<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
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
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 ImmutableArray<string> GetHeader()
Returns
ResetHeader()
Resets the header. No-op if the header is not read.
protected override void ResetHeader()