Class TabularWriter<T>
Provides forward-only, write-only access to tabular data records. This class cannot be inherited.
public sealed class TabularWriter<T> : IDisposable, IAsyncDisposable where T : notnull
Type Parameters
T
The type of an object that represents a record.
- Inheritance
-
TabularWriter<T>
- Implements
Constructors
TabularWriter(Stream, TabularDialect, TabularOptions?, TabularHandler<T>?)
Initializes a new instance of the TabularWriter<T> class for the specified stream using the provided dialect, options, and record handler.
public TabularWriter(Stream stream, TabularDialect dialect, TabularOptions? options = null, TabularHandler<T>? handler = null)
Parameters
stream
StreamThe stream to write to.
dialect
TabularDialectThe dialect to use for writing.
options
TabularOptionsThe options to control the behavior during writing.
handler
TabularHandler<T>The handler to write a
T
instance to a record.
Exceptions
- ArgumentException
stream
does not support writing.- ArgumentNullException
stream
ordialect
is null.- InvalidOperationException
The record handler is not specified and cannot be found in the registry.
Properties
BytesCommitted
Gets the number of bytes committed so far.
public long BytesCommitted { get; }
Property Value
- long
A non-negative 64-bit signed integer.
Remarks
Might be greater than the number of bytes written to the underlying stream.
RecordsWritten
Gets the number of records written so far.
public long RecordsWritten { get; }
Property Value
- long
A non-negative 64-bit signed integer.
Methods
Dispose()
Releases the resources used by the current instance of the TabularWriter<T> class.
public void Dispose()
Remarks
If the record handler defines a header, it will be automatically written.
DisposeAsync()
Asynchronously releases the resources used by the current instance of the TabularWriter<T> class.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task object.
Remarks
If the record handler defines a header, it will be automatically written.
Flush()
Writes any buffered data to the underlying stream.
public void Flush()
FlushAsync(CancellationToken)
Asynchronously writes any buffered data to the underlying stream.
public ValueTask FlushAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask
A task object.
Exceptions
- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.
WriteRecord(in T)
Writes the next record represented as T
.
public void WriteRecord(in T record)
Parameters
record
TThe record to write.
Remarks
If the record handler defines a header, it will be automatically written.
Exceptions
- ArgumentNullException
record
is null.
WriteRecordAsync(T, CancellationToken)
Asynchronously writes the next record represented as T
.
public ValueTask WriteRecordAsync(T record, CancellationToken cancellationToken = default)
Parameters
record
TThe record to write.
cancellationToken
CancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask
A task object.
Remarks
If the record handler defines a header, it will be automatically written.
Exceptions
- ArgumentNullException
record
is null.- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.