Class TabularData
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>, 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 = 65536, Encoding? encoding = null)
Parameters
streamStreamThe stream to infer from.
lineTerminatorsIEnumerable<string>The eligible values for a line terminator.
delimitersIEnumerable<char>The eligible values for a delimiter.
quoteSymbolsIEnumerable<char>The eligible values for a quote symbol.
sampleLengthintThe length of a sample in bytes.
encodingEncodingThe encoding for reading from the stream.
Returns
- TabularDialect
A successfully inferred dialect or null.
Exceptions
- ArgumentException
streamdoes not support reading.- ArgumentNullException
stream,lineTerminators,delimiters, orquoteSymbolsis 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 = 65536, Encoding? encoding = null, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream to infer from.
lineTerminatorsIEnumerable<string>The eligible values for a line terminator.
delimitersIEnumerable<char>The eligible values for a delimiter.
quoteSymbolsIEnumerable<char>The eligible values for a quote symbol.
sampleLengthintThe length of a sample in bytes.
encodingEncodingThe encoding for reading from the stream.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask<TabularDialect>
A task object that, when awaited, produces a successfully inferred dialect or null.
Exceptions
- ArgumentException
streamdoes not support reading.- ArgumentNullException
stream,lineTerminators,delimiters, orquoteSymbolsis null.
ReadRecordsAsync<T>(Stream, TabularDialect, TabularOptions?, TabularHandler<T>?, int, int, 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 = null, TabularHandler<T>? handler = null, int skip = 0, int take = 2147483647, CancellationToken cancellationToken = default) where T : notnull
Parameters
streamStreamThe stream to read from.
dialectTabularDialectThe dialect to use for reading.
optionsTabularOptionsThe options to control the behavior during reading.
handlerTabularHandler<T>The handler to read a
Tinstance from a record.skipintThe number of records to skip before returning the remaining records.
takeintThe number of records to return.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask<T[]>
A task object that, when awaited, produces an array of records.
Type Parameters
TThe type of an object that represents a record.
Exceptions
- ArgumentException
streamdoes not support reading.- ArgumentNullException
streamordialectis 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, TabularOptions?, TabularHandler<T>?, int, int)
Reads all records that can be represented as T from the stream.
public static T[] ReadRecords<T>(Stream stream, TabularDialect dialect, TabularOptions? options = null, TabularHandler<T>? handler = null, int skip = 0, int take = 2147483647) where T : notnull
Parameters
streamStreamThe stream to read from.
dialectTabularDialectThe dialect to use for reading.
optionsTabularOptionsThe options to control the behavior during reading.
handlerTabularHandler<T>The handler to read a
Tinstance from a record.skipintThe number of records to skip before returning the remaining records.
takeintThe number of records to return.
Returns
- T[]
An array of records.
Type Parameters
TThe type of an object that represents a record.
Exceptions
- ArgumentException
streamdoes not support reading.- ArgumentNullException
streamordialectis 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 = null, TabularHandler<T>? handler = null, CancellationToken cancellationToken = default) where T : notnull
Parameters
streamStreamThe stream to write to.
dialectTabularDialectThe dialect to use for writing.
recordsIEnumerable<T>The records to write to the stream.
optionsTabularOptionsThe options to control the behavior during writing.
handlerTabularHandler<T>The handler to write a
Tinstance to a record.cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask
A task object.
Type Parameters
TThe type of an object that represents a record.
Exceptions
- ArgumentException
streamdoes not support writing.- ArgumentNullException
stream,dialect, orrecordsis 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>, 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 = null, TabularHandler<T>? handler = null) where T : notnull
Parameters
streamStreamThe stream to write to.
dialectTabularDialectThe dialect to use for writing.
recordsIEnumerable<T>The records to write to the stream.
optionsTabularOptionsThe options to control the behavior during writing.
handlerTabularHandler<T>The handler to write a
Tinstance to a record.
Type Parameters
TThe type of an object that represents a record.
Exceptions
- ArgumentException
streamdoes not support writing.- ArgumentNullException
stream,dialect, orrecordsis null.- InvalidOperationException
The record handler is not specified and cannot be found in the registry.