Table of Contents

Class TabularData

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

Provides static methods for working with collections of tabular data records and inferring dialects. This class cannot be inherited.

public static class TabularData
Inheritance
TabularData

Methods

InferDialect(Stream, IEnumerable<string>, IEnumerable<char>, IEnumerable<char>)

Attempts to infer a dialect from the stream based on frequency of the eligible token values.

public static TabularDialect? InferDialect(Stream stream, IEnumerable<string> lineTerminators, IEnumerable<char> delimiters, IEnumerable<char> quoteSymbols)

Parameters

stream Stream

The stream to infer from.

lineTerminators IEnumerable<string>

The eligible values for a line terminator.

delimiters IEnumerable<char>

The eligible values for a delimiter.

quoteSymbols IEnumerable<char>

The eligible values for a quote symbol.

Returns

TabularDialect

A successfully inferred dialect or null.

Remarks

The operation consumes the first 65536 bytes as a sample and uses a UTF-8 encoding without byte order mark (BOM).

Exceptions

ArgumentException

stream does not support reading.

ArgumentNullException

stream, lineTerminators, delimiters, or quoteSymbols is null.

InferDialect(Stream, IEnumerable<string>, IEnumerable<char>, IEnumerable<char>, int, Encoding?)

Attempts to infer a dialect from the stream based on frequency of the eligible token values.

public static TabularDialect? InferDialect(Stream stream, IEnumerable<string> lineTerminators, IEnumerable<char> delimiters, IEnumerable<char> quoteSymbols, int sampleLength, Encoding? encoding)

Parameters

stream Stream

The stream to infer from.

lineTerminators IEnumerable<string>

The eligible values for a line terminator.

delimiters IEnumerable<char>

The eligible values for a delimiter.

quoteSymbols IEnumerable<char>

The eligible values for a quote symbol.

sampleLength int

The length of a sample in bytes.

encoding Encoding

The encoding for reading from the stream.

Returns

TabularDialect

A successfully inferred dialect or null.

Exceptions

ArgumentException

stream does not support reading.

ArgumentNullException

stream, lineTerminators, delimiters, or quoteSymbols is null.

InferDialectAsync(Stream, IEnumerable<string>, IEnumerable<char>, IEnumerable<char>, int, Encoding?, CancellationToken)

Asynchronously attempts to infer a dialect from the stream based on frequency of the eligible token values.

public static ValueTask<TabularDialect?> InferDialectAsync(Stream stream, IEnumerable<string> lineTerminators, IEnumerable<char> delimiters, IEnumerable<char> quoteSymbols, int sampleLength, Encoding? encoding, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to infer from.

lineTerminators IEnumerable<string>

The eligible values for a line terminator.

delimiters IEnumerable<char>

The eligible values for a delimiter.

quoteSymbols IEnumerable<char>

The eligible values for a quote symbol.

sampleLength int

The length of a sample in bytes.

encoding Encoding

The encoding for reading from the stream.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<TabularDialect>

A task object that, when awaited, produces a successfully inferred dialect or null.

Exceptions

ArgumentException

stream does not support reading.

ArgumentNullException

stream, lineTerminators, delimiters, or quoteSymbols is null.

InferDialectAsync(Stream, IEnumerable<string>, IEnumerable<char>, IEnumerable<char>, CancellationToken)

Asynchronously attempts to infer a dialect from the stream based on frequency of the eligible token values.

public static ValueTask<TabularDialect?> InferDialectAsync(Stream stream, IEnumerable<string> lineTerminators, IEnumerable<char> delimiters, IEnumerable<char> quoteSymbols, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to infer from.

lineTerminators IEnumerable<string>

The eligible values for a line terminator.

delimiters IEnumerable<char>

The eligible values for a delimiter.

quoteSymbols IEnumerable<char>

The eligible values for a quote symbol.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<TabularDialect>

A task object that, when awaited, produces a successfully inferred dialect or null.

Remarks

The operation consumes the first 65536 bytes as a sample and uses a UTF-8 encoding without byte order mark (BOM).

Exceptions

ArgumentException

stream does not support reading.

ArgumentNullException

stream, lineTerminators, delimiters, or quoteSymbols is null.

ReadRecordsAsync<T>(Stream, TabularDialect, TabularOptions?, TabularHandler<T>?, CancellationToken)

Asynchronously reads all records from the stream that can be represented as T.

public static ValueTask<T[]> ReadRecordsAsync<T>(Stream stream, TabularDialect dialect, TabularOptions? options, TabularHandler<T>? handler, CancellationToken cancellationToken = default) where T : notnull

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.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<T[]>

A task object that, when awaited, produces an array of records.

Type Parameters

T

The type of an object that represents 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.

OperationCanceledException

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

TabularContentException

An unexpected character or end of stream was encountered.

ReadRecordsAsync<T>(Stream, TabularDialect, TabularOptions?, CancellationToken)

Asynchronously reads all records from the stream that can be represented as T.

public static ValueTask<T[]> ReadRecordsAsync<T>(Stream stream, TabularDialect dialect, TabularOptions? options, CancellationToken cancellationToken = default) where T : notnull

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.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<T[]>

A task object that, when awaited, produces an array of records.

Type Parameters

T

The type of an object that represents 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.

OperationCanceledException

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

TabularContentException

An unexpected character or end of stream was encountered.

ReadRecordsAsync<T>(Stream, TabularDialect, CancellationToken)

Asynchronously reads all records from the stream that can be represented as T.

public static ValueTask<T[]> ReadRecordsAsync<T>(Stream stream, TabularDialect dialect, CancellationToken cancellationToken = default) where T : notnull

Parameters

stream Stream

The stream to read from.

dialect TabularDialect

The dialect to use for reading.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<T[]>

A task object that, when awaited, produces an array of records.

Type Parameters

T

The type of an object that represents 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.

OperationCanceledException

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

TabularContentException

An unexpected character or end of stream was encountered.

ReadRecords<T>(Stream, TabularDialect)

Reads all records from the stream that can be represented as T.

public static T[] ReadRecords<T>(Stream stream, TabularDialect dialect) where T : notnull

Parameters

stream Stream

The stream to read from.

dialect TabularDialect

The dialect to use for reading.

Returns

T[]

An array of records.

Type Parameters

T

The type of an object that represents 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.

TabularContentException

An unexpected character or end of stream was encountered.

ReadRecords<T>(Stream, TabularDialect, TabularOptions?)

Reads all records that can be represented as T from the stream.

public static T[] ReadRecords<T>(Stream stream, TabularDialect dialect, TabularOptions? options) where T : notnull

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.

Returns

T[]

An array of records.

Type Parameters

T

The type of an object that represents 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.

TabularContentException

An unexpected character or end of stream was encountered.

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

Reads all records that can be represented as T from the stream.

public static T[] ReadRecords<T>(Stream stream, TabularDialect dialect, TabularOptions? options, TabularHandler<T>? handler) where T : notnull

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.

Returns

T[]

An array of records.

Type Parameters

T

The type of an object that represents 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.

TabularContentException

An unexpected character or end of stream was encountered.

WriteRecordsAsync<T>(Stream, TabularDialect, IEnumerable<T>, TabularOptions?, TabularHandler<T>?, CancellationToken)

Asynchronously writes a collection of records to the stream.

public static ValueTask WriteRecordsAsync<T>(Stream stream, TabularDialect dialect, IEnumerable<T> records, TabularOptions? options, TabularHandler<T>? handler, CancellationToken cancellationToken = default) where T : notnull

Parameters

stream Stream

The stream to write to.

dialect TabularDialect

The dialect to use for writing.

records IEnumerable<T>

The records to write to the stream.

options TabularOptions

The options to control the behavior during writing.

handler TabularHandler<T>

The handler to write a T instance to a record.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask

A task object.

Type Parameters

T

The type of an object that represents a record.

Exceptions

ArgumentException

stream does not support writing.

ArgumentNullException

stream, dialect, or records is null.

InvalidOperationException

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

OperationCanceledException

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

WriteRecordsAsync<T>(Stream, TabularDialect, IEnumerable<T>, TabularOptions?, CancellationToken)

Asynchronously writes a collection of records to the stream.

public static ValueTask WriteRecordsAsync<T>(Stream stream, TabularDialect dialect, IEnumerable<T> records, TabularOptions? options, CancellationToken cancellationToken = default) where T : notnull

Parameters

stream Stream

The stream to write to.

dialect TabularDialect

The dialect to use for writing.

records IEnumerable<T>

The records to write to the stream.

options TabularOptions

The options to control the behavior during writing.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask

A task object.

Type Parameters

T

The type of an object that represents a record.

Exceptions

ArgumentException

stream does not support writing.

ArgumentNullException

stream, dialect, or records is null.

InvalidOperationException

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

OperationCanceledException

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

WriteRecordsAsync<T>(Stream, TabularDialect, IEnumerable<T>, CancellationToken)

Asynchronously writes a collection of records to the stream.

public static ValueTask WriteRecordsAsync<T>(Stream stream, TabularDialect dialect, IEnumerable<T> records, CancellationToken cancellationToken = default) where T : notnull

Parameters

stream Stream

The stream to write to.

dialect TabularDialect

The dialect to use for writing.

records IEnumerable<T>

The records to write to the stream.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask

A task object.

Type Parameters

T

The type of an object that represents a record.

Exceptions

ArgumentException

stream does not support writing.

ArgumentNullException

stream, dialect, or records is null.

InvalidOperationException

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

OperationCanceledException

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

WriteRecords<T>(Stream, TabularDialect, IEnumerable<T>)

Writes a collection of records to the stream.

public static void WriteRecords<T>(Stream stream, TabularDialect dialect, IEnumerable<T> records) where T : notnull

Parameters

stream Stream

The stream to write to.

dialect TabularDialect

The dialect to use for writing.

records IEnumerable<T>

The records to write to the stream.

Type Parameters

T

The type of an object that represents a record.

Exceptions

ArgumentException

stream does not support writing.

ArgumentNullException

stream, dialect, or records is null.

InvalidOperationException

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

WriteRecords<T>(Stream, TabularDialect, IEnumerable<T>, TabularOptions?)

Writes a collection of records to the stream.

public static void WriteRecords<T>(Stream stream, TabularDialect dialect, IEnumerable<T> records, TabularOptions? options) where T : notnull

Parameters

stream Stream

The stream to write to.

dialect TabularDialect

The dialect to use for writing.

records IEnumerable<T>

The records to write to the stream.

options TabularOptions

The options to control the behavior during writing.

Type Parameters

T

The type of an object that represents a record.

Exceptions

ArgumentException

stream does not support writing.

ArgumentNullException

stream, dialect, or records is null.

InvalidOperationException

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

WriteRecords<T>(Stream, TabularDialect, IEnumerable<T>, TabularOptions?, TabularHandler<T>?)

Writes a collection of records to the stream.

public static void WriteRecords<T>(Stream stream, TabularDialect dialect, IEnumerable<T> records, TabularOptions? options, TabularHandler<T>? handler) where T : notnull

Parameters

stream Stream

The stream to write to.

dialect TabularDialect

The dialect to use for writing.

records IEnumerable<T>

The records to write to the stream.

options TabularOptions

The options to control the behavior during writing.

handler TabularHandler<T>

The handler to write a T instance to a record.

Type Parameters

T

The type of an object that represents a record.

Exceptions

ArgumentException

stream does not support writing.

ArgumentNullException

stream, dialect, or records is null.

InvalidOperationException

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