Struct CsvRecord<T>
- Namespace
- FlameCsv
- Assembly
- FlameCsv.Core.dll
Represents the current record when reading CSV.
[DebuggerTypeProxy(typeof(CsvRecord<>.CsvRecordDebugView))]
public readonly struct CsvRecord<T> : IEnumerable<ReadOnlySpan<T>>, IEnumerable, IDataRecord where T : unmanaged, IBinaryInteger<T>
Type Parameters
TToken type
- Implements
Properties
FieldCount
Returns the number of fields in the record; always at least 1 in a valid record, even if the record's length is 0.
Returns 0 if the struct is default.
public int FieldCount { get; }
Property Value
Header
Returns the header record for the current CSV, or null if HasHeader is false.
public CsvHeader? Header { get; }
Property Value
this[CsvFieldIdentifier]
Returns the value of the field at the specified index.
public ReadOnlySpan<T> this[CsvFieldIdentifier id] { get; }
Parameters
idCsvFieldIdentifierField 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
idpoints to a header name, but the CSV has no header
LineNumber
Returns the 1-based line number of the record in the source data. Header records are counted.
public int LineNumber { get; }
Property Value
Remarks
Lines are counted as CSV records; newlines inside quoted fields are not counted.
Options
The options-instance associated with the current CSV.
public CsvOptions<T> Options { get; }
Property Value
- CsvOptions<T>
Position
Returns the 0-based position of the start of the first field of the record in the source data. Header records are counted.
public long Position { get; }
Property Value
Remarks
If T is char, this is the character position, even if the data is from a byte stream.
Raw
Raw data of the record as a single memory block, not including a possible trailing newline.
public ReadOnlySpan<T> Raw { get; }
Property Value
- ReadOnlySpan<T>
Methods
Contains(CsvFieldIdentifier)
Returns true if the record contains the specified field.
public bool Contains(CsvFieldIdentifier id)
Parameters
Returns
GetEnumerator()
Returns an enumerator that can be used to read the fields one by one.
public CsvRecord<T>.Enumerator GetEnumerator()
Returns
GetField(CsvFieldIdentifier)
Returns the value of the field at the specified index.
public ReadOnlySpan<T> GetField(CsvFieldIdentifier id)
Parameters
idCsvFieldIdentifierField 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
idpoints 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
converterCsvConverter<T, TValue>Converter to parse the field with
idCsvFieldIdentifierField index of name
Returns
- TValue
Parsed value
Type Parameters
TValueValue 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
idCsvFieldIdentifierField index of name
Returns
- TValue
Parsed value
Type Parameters
TValueValue 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
typeMapCsvTypeMap<T, TRecord>
Returns
- TRecord
Type Parameters
TRecord
ToArray()
Copies the fields in the record to a new array.
public string[] ToArray()
Returns
- string[]
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
converterCsvConverter<T, TValue>Converter to parse the field with
idCsvFieldIdentifierField index of name
valueTValueParsed value, if successful
Returns
- bool
trueif the value was successfully parsed
Type Parameters
TValueValue 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
idCsvFieldIdentifierField index of name
valueTValueParsed value, if successful
Returns
- bool
trueif the value was successfully parsed
Type Parameters
TValueValue parsed
Exceptions
- ArgumentException
The ID points to a field that does not exist
- CsvConverterMissingException
Converter not found for
TValue
Operators
explicit operator CsvRecordRef<T>(in CsvRecord<T>)
Converts to a CsvRecordRef<T>.
public static explicit operator CsvRecordRef<T>(in CsvRecord<T> record)
Parameters
recordCsvRecord<T>
Returns
- CsvRecordRef<T>