Class TabularReader
Provides forward-only, read-only access to tabular data fields. This class cannot be inherited.
public sealed class TabularReader : IDisposable, IAsyncDisposable
- Inheritance
-
TabularReader
- Implements
Constructors
TabularReader(Stream, TabularDialect, TabularOptions?)
Initializes a new instance of the TabularReader class for the specified stream using the provided dialect and options.
public TabularReader(Stream stream, TabularDialect dialect, TabularOptions? options = null)
Parameters
stream
StreamThe stream to read from.
dialect
TabularDialectThe dialect to use for reading.
options
TabularOptionsThe options to control the behavior during reading.
Exceptions
- ArgumentException
stream
does not support reading.- ArgumentNullException
stream
ordialect
is null.
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.
CurrentField
Gets the last read field as a character sequence.
public ReadOnlyMemory<char> CurrentField { get; }
Property Value
- ReadOnlyMemory<char>
A read-only region of memory.
CurrentFieldType
Gets the type of the last consumed field.
public TabularFieldType CurrentFieldType { get; }
Property Value
- TabularFieldType
A field type enumeration value.
CurrentPositionType
Gets the type of the current reader position.
public TabularPositionType CurrentPositionType { get; }
Property Value
- TabularPositionType
A position type enumeration value.
FieldsRead
Gets the number of fields read from the current record so far.
public long FieldsRead { get; }
Property Value
- long
A non-negative 64-bit signed integer.
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 class.
public void Dispose()
DisposeAsync()
Asynchronously releases the resources used by the current instance of the TabularReader class.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task object.
GetBase16Binary()
Parses the current field as binary data encoded with "base16" ("hex") encoding.
public byte[] GetBase16Binary()
Returns
- byte[]
An array of bytes.
Remarks
The field must be formatted according to the RFC 4648. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an array of bytes using "base16" ("hex") encoding.
GetBase64Binary()
Parses the current field as binary data encoded with "base64" encoding.
public byte[] GetBase64Binary()
Returns
- byte[]
An array of bytes.
Remarks
The field must be formatted according to the RFC 4648. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an array of bytes using "base64" encoding.
GetBigInteger()
Parses the current field as BigInteger.
public BigInteger GetBigInteger()
Returns
- BigInteger
A BigInteger value.
Remarks
Leading and trailing white-space characters, group separators are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a BigInteger value.
GetBoolean()
Parses the current field as bool.
public bool GetBoolean()
Returns
Remarks
The field must be represented as one of the literals: "false"
, "true"
, "0"
, "1"
. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a bool value.
GetByte()
Parses the current field as byte.
public byte GetByte()
Returns
Remarks
Leading and trailing white-space characters, percent sign are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a byte value.
GetChar()
Parses the current field as char.
public char GetChar()
Returns
Remarks
The field must be represented as one UTF-16 code unit.
Exceptions
- FormatException
The current field cannot be parsed as a char value.
GetDateOnly()
Parses the current field as DateOnly.
public DateOnly GetDateOnly()
Returns
Remarks
The field must be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a DateOnly value.
GetDateTime()
Parses the current field as DateTime.
public DateTime GetDateTime()
Returns
Remarks
The field must be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a DateTime value.
GetDateTimeOffset()
Parses the current field as DateTimeOffset.
public DateTimeOffset GetDateTimeOffset()
Returns
- DateTimeOffset
A DateTimeOffset value.
Remarks
The field must be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a DateTimeOffset value.
GetDecimal()
Parses the current field as decimal.
public decimal GetDecimal()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a decimal value.
GetDouble()
Parses the current field as double.
public double GetDouble()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a double value.
GetGuid()
Parses the current field as Guid.
public Guid GetGuid()
Returns
Remarks
The field must be formatted according to the RFC 4122. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a Guid value.
GetHalf()
Parses the current field as Half.
public Half GetHalf()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a Half value.
GetInt128()
Parses the current field as an Int128.
public Int128 GetInt128()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an Int128 value.
GetInt16()
Parses the current field as short.
public short GetInt16()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a short value.
GetInt32()
Parses the current field as an int.
public int GetInt32()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an int value.
GetInt64()
Parses the current field as long.
public long GetInt64()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a long value.
GetSByte()
Parses the current field as sbyte.
[CLSCompliant(false)]
public sbyte GetSByte()
Returns
Remarks
Leading and trailing white-space characters, percent sign are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a sbyte value.
GetSingle()
Parses the current field as float.
public float GetSingle()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a float value.
GetString()
Transcodes the current field as string.
public string GetString()
Returns
Exceptions
- FormatException
The current field cannot be transcoded as string.
GetTimeOnly()
Parses the current field as TimeOnly.
public TimeOnly GetTimeOnly()
Returns
Remarks
The field must be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a TimeOnly value.
GetTimeSpan()
Parses the current field as TimeSpan.
public TimeSpan GetTimeSpan()
Returns
Remarks
The field must be formatted according to the RFC 3339 and include only "D"
, "H"
, "M"
, or "S"
designators. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as a TimeSpan value.
GetUInt128()
Parses the current field as an UInt128.
[CLSCompliant(false)]
public UInt128 GetUInt128()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an UInt128 value.
GetUInt16()
Parses the current field as an ushort.
[CLSCompliant(false)]
public ushort GetUInt16()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an ushort value.
GetUInt32()
Parses the current field as an uint.
[CLSCompliant(false)]
public uint GetUInt32()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an uint value.
GetUInt64()
Parses the current field as an ulong.
[CLSCompliant(false)]
public ulong GetUInt64()
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an ulong value.
GetUri()
Parses the current field as System.Uri.
public Uri GetUri()
Returns
- Uri
An System.Uri instance.
Remarks
The field must be formatted according to the RFC 3986. Leading and trailing white-space characters are allowed.
Exceptions
- FormatException
The current field cannot be parsed as an System.Uri instance.
Get<T>(TabularConverter<T?>)
Parses the current field as T
.
public T? Get<T>(TabularConverter<T?> converter)
Parameters
converter
TabularConverter<T>The converter to parse the value with.
Returns
- T
A
T
value.
Type Parameters
T
The type to parse the field as.
Exceptions
- ArgumentNullException
converter
is null.- FormatException
The current field cannot be parsed as
T
.
TryGetBase16Binary(out byte[]?)
Tries to parse the current field as binary data encoded with "base16" ("hex") encoding and returns a value that indicates whether the operation succeeded.
public bool TryGetBase16Binary(out byte[]? value)
Parameters
value
byte[]When this method returns, contains an array of bytes that represents the current field, or null on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 4648. Leading and trailing white-space characters are allowed.
TryGetBase64Binary(out byte[]?)
Tries to parse the current field as binary data encoded with "base64" encoding and returns a value that indicates whether the operation succeeded.
public bool TryGetBase64Binary(out byte[]? value)
Parameters
value
byte[]When this method returns, contains an array of bytes that represents the current field, or null on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 4648. Leading and trailing white-space characters are allowed.
TryGetBigInteger(out BigInteger)
Tries to parse the current field as BigInteger and returns a value that indicates whether the operation succeeded.
public bool TryGetBigInteger(out BigInteger value)
Parameters
value
BigIntegerWhen this method returns, contains a BigInteger value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators are allowed.
TryGetBoolean(out bool)
Tries to parse the current field as bool and returns a value that indicates whether the operation succeeded.
public bool TryGetBoolean(out bool value)
Parameters
value
boolWhen this method returns, contains a bool value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be represented as one of the literals: "false"
, "true"
, "0"
, "1"
. Leading and trailing white-space characters are allowed.
TryGetByte(out byte)
Tries to parse the current field as byte and returns a value that indicates whether the operation succeeded.
public bool TryGetByte(out byte value)
Parameters
value
byteWhen this method returns, contains a byte value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, percent sign are allowed.
TryGetChar(out char)
Tries to parse the current field as char and returns a value that indicates whether the operation succeeded.
public bool TryGetChar(out char value)
Parameters
value
charWhen this method returns, contains a char value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be represented as one UTF-16 code unit.
TryGetDateOnly(out DateOnly)
Tries to parse the current field as DateOnly and returns a value that indicates whether the operation succeeded.
public bool TryGetDateOnly(out DateOnly value)
Parameters
value
DateOnlyWhen this method returns, contains a DateOnly value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
TryGetDateTime(out DateTime)
Tries to parse the current field as DateTime and returns a value that indicates whether the operation succeeded.
public bool TryGetDateTime(out DateTime value)
Parameters
value
DateTimeWhen this method returns, contains a DateTime value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
TryGetDateTimeOffset(out DateTimeOffset)
Tries to parse the current field as DateTimeOffset and returns a value that indicates whether the operation succeeded.
public bool TryGetDateTimeOffset(out DateTimeOffset value)
Parameters
value
DateTimeOffsetWhen this method returns, contains a DateTimeOffset value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
TryGetDecimal(out decimal)
Tries to parse the current field as decimal and returns a value that indicates whether the operation succeeded.
public bool TryGetDecimal(out decimal value)
Parameters
value
decimalWhen this method returns, contains a decimal value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetDouble(out double)
Tries to parse the current field as double and returns a value that indicates whether the operation succeeded.
public bool TryGetDouble(out double value)
Parameters
value
doubleWhen this method returns, contains a double value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetGuid(out Guid)
Tries to parse the current field as Guid and returns a value that indicates whether the operation succeeded.
public bool TryGetGuid(out Guid value)
Parameters
value
GuidWhen this method returns, contains a Guid value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 4122. Leading and trailing white-space characters are allowed.
TryGetHalf(out Half)
Tries to parse the current field as Half and returns a value that indicates whether the operation succeeded.
public bool TryGetHalf(out Half value)
Parameters
value
HalfWhen this method returns, contains a Half value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetInt128(out Int128)
Tries to parse the current field as Int128 and returns a value that indicates whether the operation succeeded.
public bool TryGetInt128(out Int128 value)
Parameters
value
Int128When this method returns, contains a Int128 value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetInt16(out short)
Tries to parse the current field as short and returns a value that indicates whether the operation succeeded.
public bool TryGetInt16(out short value)
Parameters
value
shortWhen this method returns, contains a short value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetInt32(out int)
Tries to parse the current field as int and returns a value that indicates whether the operation succeeded.
public bool TryGetInt32(out int value)
Parameters
value
intWhen this method returns, contains a int value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetInt64(out long)
Tries to parse the current field as long and returns a value that indicates whether the operation succeeded.
public bool TryGetInt64(out long value)
Parameters
value
longWhen this method returns, contains a long value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetSByte(out sbyte)
Tries to parse the current field as sbyte and returns a value that indicates whether the operation succeeded.
[CLSCompliant(false)]
public bool TryGetSByte(out sbyte value)
Parameters
value
sbyteWhen this method returns, contains a sbyte value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, percent sign are allowed.
TryGetSingle(out float)
Tries to parse the current field as float and returns a value that indicates whether the operation succeeded.
public bool TryGetSingle(out float value)
Parameters
value
floatWhen this method returns, contains a float value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetString(out string?)
Tries to transcode the current field as string and returns a value that indicates whether the operation succeeded.
public bool TryGetString(out string? value)
Parameters
value
stringWhen this method returns, contains a string instance that represents the current field, or null. This parameter is treated as uninitialized.
Returns
TryGetTimeOnly(out TimeOnly)
Tries to parse the current field as TimeOnly and returns a value that indicates whether the operation succeeded.
public bool TryGetTimeOnly(out TimeOnly value)
Parameters
value
TimeOnlyWhen this method returns, contains a TimeOnly value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 3339. Leading and trailing white-space characters are allowed.
TryGetTimeSpan(out TimeSpan)
Tries to parse the current field as TimeSpan and returns a value that indicates whether the operation succeeded.
public bool TryGetTimeSpan(out TimeSpan value)
Parameters
value
TimeSpanWhen this method returns, contains a TimeSpan value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 3339 and include only "D"
, "H"
, "M"
, or "S"
designators. Leading and trailing white-space characters are allowed.
TryGetUInt128(out UInt128)
Tries to parse the current field as UInt128 and returns a value that indicates whether the operation succeeded.
[CLSCompliant(false)]
public bool TryGetUInt128(out UInt128 value)
Parameters
value
UInt128When this method returns, contains a UInt128 value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetUInt16(out ushort)
Tries to parse the current field as ushort and returns a value that indicates whether the operation succeeded.
[CLSCompliant(false)]
public bool TryGetUInt16(out ushort value)
Parameters
value
ushortWhen this method returns, contains a ushort value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetUInt32(out uint)
Tries to parse the current field as uint and returns a value that indicates whether the operation succeeded.
[CLSCompliant(false)]
public bool TryGetUInt32(out uint value)
Parameters
value
uintWhen this method returns, contains a uint value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetUInt64(out ulong)
Tries to parse the current field as ulong and returns a value that indicates whether the operation succeeded.
[CLSCompliant(false)]
public bool TryGetUInt64(out ulong value)
Parameters
value
ulongWhen this method returns, contains a ulong value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Remarks
Leading and trailing white-space characters, group separators, percent and per mille signs are allowed.
TryGetUri(out Uri?)
Tries to parse the current field as System.Uri and returns a value that indicates whether the operation succeeded.
public bool TryGetUri(out Uri? value)
Parameters
value
UriWhen this method returns, contains an System.Uri instance that represents the current field, or null on failure. This parameter is treated as uninitialized.
Returns
Remarks
The value should be formatted according to the RFC 3986. Leading and trailing white-space characters are allowed.
TryGet<T>(TabularConverter<T?>, out T?)
Tries to parse the current field as T
and returns a value that indicates whether the operation succeeded.
public bool TryGet<T>(TabularConverter<T?> converter, out T? value)
Parameters
converter
TabularConverter<T>The converter to parse the value with.
value
TWhen this method returns, contains a
T
value that represents the current field, or an undefined value on failure. This parameter is treated as uninitialized.
Returns
Type Parameters
T
The type to parse the field as.
Exceptions
- ArgumentNullException
converter
is null.
TryPickRecord()
Tries to switch the reader to the next record.
public bool TryPickRecord()
Returns
TryReadField()
Tries to read the content of the next field of the current record.
public bool TryReadField()
Returns
Exceptions
- TabularContentException
An unexpected character or end of stream was encountered.
TryReadFieldAsync(CancellationToken)
Asynchronously tries to read the content of the next field of the current record.
public ValueTask<bool> TryReadFieldAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask<bool>
A task object that, when awaited, produces true if the field was successfully read; 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.
TrySkipField()
Tries to advance the reader to the next field of the current record.
public bool TrySkipField()
Returns
Exceptions
- TabularContentException
An unexpected character or end of stream was encountered.
TrySkipFieldAsync(CancellationToken)
Asynchronously tries to advance the reader to the next field of the current record.
public ValueTask<bool> TrySkipFieldAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe 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.