Table of Contents

Class TabularReader<T>

Namespace
Addax.Formats.Tabular
Assembly
Addax.Formats.Tabular.dll

Provides forward-only, read-only access to tabular data records. This class cannot be inherited.

public sealed class TabularReader<T> : IDisposable, IAsyncDisposable where T : notnull

Type Parameters

T

The type of an object that represents a record.

Inheritance
TabularReader<T>
Implements

Constructors

TabularReader(Stream, TabularDialect, TabularOptions?, TabularHandler<T>?)

Initializes a new instance of the TabularReader<T> class for the specified stream using the provided dialect, options, and record handler.

public TabularReader(Stream stream, TabularDialect dialect, TabularOptions? options = null, TabularHandler<T>? handler = null)

Parameters

stream Stream

The stream to read from.

dialect TabularDialect

The dialect to use for reading.

options TabularOptions

The options to control the behavior during reading.

handler TabularHandler<T>

The handler to read a T instance from a record.

Exceptions

ArgumentException

stream does not support reading.

ArgumentNullException

stream or dialect is null.

InvalidOperationException

The record handler is not specified and cannot be found in the registry.

Properties

BytesConsumed

Gets the number of bytes consumed so far.

public long BytesConsumed { get; }

Property Value

long

A non-negative 64-bit signed integer.

Remarks

Might be less than the number of bytes read from the underlying stream.

CurrentRecord

Gets the last read record that is represented as T.

public T CurrentRecord { get; }

Property Value

T

A T instance. An exception is thrown if the current record is not set.

Exceptions

InvalidOperationException

The current record is not set.

CurrentRecordRef

Gets a reference to the last read record that is represented as T.

public ref readonly T CurrentRecordRef { get; }

Property Value

T

A read-only reference to a T instance. An exception is thrown if the current record is not set.

Exceptions

InvalidOperationException

The current record is not set.

RecordsRead

Gets the number of records read so far.

public long RecordsRead { get; }

Property Value

long

A non-negative 64-bit signed integer.

Methods

Dispose()

Releases the resources used by the current instance of the TabularReader<T> class.

public void Dispose()

DisposeAsync()

Asynchronously releases the resources used by the current instance of the TabularReader<T> class.

public ValueTask DisposeAsync()

Returns

ValueTask

A task object.

TryReadRecord()

Tries to read the next record that can be represented as T.

public bool TryReadRecord()

Returns

bool

true if the record was successfully read; otherwise, false.

Remarks

If the record handler defines a header, the first record will be automatically skipped.

Exceptions

TabularContentException

An unexpected character or end of stream was encountered.

TryReadRecordAsync(CancellationToken)

Asynchronously reads the next record that can be represented as T.

public ValueTask<bool> TryReadRecordAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<bool>

A task object that, when awaited, produces true if the record was successfully read; otherwise, false.

Remarks

If the record handler defines a header, the first record will be automatically skipped.

Exceptions

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

TabularContentException

An unexpected character or end of stream was encountered. This exception is stored into the returned task.

TrySkipRecord()

Tries to advance the reader to the next record.

public bool TrySkipRecord()

Returns

bool

true if the reader was successfully advanced; otherwise, false.

Exceptions

TabularContentException

An unexpected character or end of stream was encountered.

TrySkipRecordAsync(CancellationToken)

Asynchronously tries to advance the reader to the next record.

public ValueTask<bool> TrySkipRecordAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<bool>

A task object that, when awaited, produces true if the reader was successfully advanced; otherwise, false.

Exceptions

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

TabularContentException

An unexpected character or end of stream was encountered. This exception is stored into the returned task.