Struct CsvValueRecord<T>
- Namespace
- FlameCsv
- Assembly
- FlameCsv.Core.dll
Represents the current record when reading CSV.
[DebuggerTypeProxy(typeof(CsvValueRecord<>.CsvRecordDebugView))]
public readonly struct CsvValueRecord<T> : ICsvFields<T> where T : unmanaged, IBinaryInteger<T>
Type Parameters
T
Token type
- Implements
-
ICsvFields<T>
Properties
FieldCount
Returns the number of fields in the record.
public int FieldCount { get; }
Property Value
HasHeader
Returns true if the header has been parsed from the CSV the record and Header is safe to use.
public bool HasHeader { get; }
Property Value
Remarks
The header isn't returned as a separate record, so this property is always true if the options-instance is configured to have a header, and always false if not.
Header
public ReadOnlySpan<string> Header { get; }
Property Value
Exceptions
- NotSupportedException
Options is configured not to have a header
- See Also
this[CsvFieldIdentifier]
Returns the value of the field at the specified index.
public ReadOnlySpan<T> this[CsvFieldIdentifier id] { get; }
Parameters
id
CsvFieldIdentifierField index of name
Property Value
- ReadOnlySpan<T>
Field value, unescaped and stripped of quotes when applicable
Exceptions
- ArgumentException
The ID points to a field that does not exist
- NotSupportedException
id
points to a header name, but the CSV has no header
Line
1-based line number in the CSV data. Empty lines and the header are counted.
public int Line { get; }
Property Value
Options
The options-instance associated with the current CSV.
public CsvOptions<T> Options { get; }
Property Value
- CsvOptions<T>
Position
Start position of the record in the original data.
public long Position { get; }
Property Value
RawRecord
Raw data of the record as a single memory block, not including a possible trailing newline.
public ReadOnlySpan<T> RawRecord { get; }
Property Value
- ReadOnlySpan<T>
Methods
Contains(CsvFieldIdentifier)
Returns true if the record contains the specified field.
public bool Contains(CsvFieldIdentifier id)
Parameters
Returns
Remarks
This method does not throw even if the identifier is for a header name, but the record's CSV has no header.
GetEnumerator()
Returns an enumerator that can be used to read the fields one by one.
public CsvValueRecord<T>.Enumerator GetEnumerator()
Returns
GetField(CsvFieldIdentifier)
Returns the value of the field at the specified index.
public ReadOnlySpan<T> GetField(CsvFieldIdentifier id)
Parameters
id
CsvFieldIdentifierField index of name
Returns
- ReadOnlySpan<T>
Field value, unescaped and stripped of quotes when applicable
Exceptions
- ArgumentException
The ID points to a field that does not exist
- NotSupportedException
id
points to a header name, but the CSV has no header
ParseField<TValue>(CsvConverter<T, TValue>, CsvFieldIdentifier)
Parses a value of type TValue
from a specific field.
public TValue ParseField<TValue>(CsvConverter<T, TValue> converter, CsvFieldIdentifier id)
Parameters
converter
CsvConverter<T, TValue>Converter to parse the field with
id
CsvFieldIdentifierField index of name
Returns
- TValue
Parsed value
Type Parameters
TValue
Value parsed
Exceptions
- ArgumentException
The ID points to a field that does not exist
- CsvConverterMissingException
Converter not found for
TValue
- CsvParseException
The field value could not be parsed
ParseField<TValue>(CsvFieldIdentifier)
Parses a value of type TValue
from a specific field.
[RequiresUnreferencedCode("This code path may require types that cannot be statically analyzed and might need runtime code generation. Use an alternative overload for native AOT applications.")]
[RequiresDynamicCode("This code path may require types that cannot be statically analyzed and might need runtime code generation. Use an alternative overload for native AOT applications.")]
public TValue ParseField<TValue>(CsvFieldIdentifier id)
Parameters
id
CsvFieldIdentifierField index of name
Returns
- TValue
Parsed value
Type Parameters
TValue
Value parsed
Exceptions
- ArgumentException
The ID points to a field that does not exist
- CsvConverterMissingException
Converter not found for
TValue
- CsvParseException
The field value could not be parsed
ParseRecord<TRecord>()
Parses the record into an instance of TRecord
using reflection.
[RequiresUnreferencedCode("This code path uses reflection. Use the overloads accepting source generated CsvTypeMap for AOT/trimming compatible code.")]
[RequiresDynamicCode("This code path uses compiled expressions. Use the overloads accepting source generated CsvTypeMap for AOT/trimming compatible code.")]
public TRecord ParseRecord<TRecord>()
Returns
- TRecord
Type Parameters
TRecord
ParseRecord<TRecord>(CsvTypeMap<T, TRecord>)
Parses the record into an instance of TRecord
by using the type map.
public TRecord ParseRecord<TRecord>(CsvTypeMap<T, TRecord> typeMap)
Parameters
typeMap
CsvTypeMap<T, TRecord>
Returns
- TRecord
Type Parameters
TRecord
Preserve()
Preserves the data in the value record.
public CsvRecord<T> Preserve()
Returns
- CsvRecord<T>
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
TryParseField<TValue>(CsvConverter<T, TValue>, CsvFieldIdentifier, out TValue)
Attempts to parse a TValue
from a specific field.
public bool TryParseField<TValue>(CsvConverter<T, TValue> converter, CsvFieldIdentifier id, out TValue value)
Parameters
converter
CsvConverter<T, TValue>Converter to parse the field with
id
CsvFieldIdentifierField index of name
value
TValueParsed value, if successful
Returns
Type Parameters
TValue
Value parsed
Exceptions
- ArgumentException
The ID points to a field that does not exist
- CsvConverterMissingException
Converter not found for
TValue
TryParseField<TValue>(CsvFieldIdentifier, out TValue)
Attempts to parse a TValue
from a specific field.
[RequiresUnreferencedCode("This code path may require types that cannot be statically analyzed and might need runtime code generation. Use an alternative overload for native AOT applications.")]
[RequiresDynamicCode("This code path may require types that cannot be statically analyzed and might need runtime code generation. Use an alternative overload for native AOT applications.")]
public bool TryParseField<TValue>(CsvFieldIdentifier id, out TValue value)
Parameters
id
CsvFieldIdentifierField index of name
value
TValueParsed value, if successful
Returns
Type Parameters
TValue
Value parsed
Exceptions
- ArgumentException
The ID points to a field that does not exist
- CsvConverterMissingException
Converter not found for
TValue
Operators
explicit operator CsvRecord<T>(in CsvValueRecord<T>)
Preserves the data in the value record.
public static explicit operator CsvRecord<T>(in CsvValueRecord<T> record)
Parameters
record
CsvValueRecord<T>
Returns
- CsvRecord<T>