Class CsvPreservedRecord<T>
- Namespace
- FlameCsv
- Assembly
- FlameCsv.Core.dll
A preserved copy of the data in a CSV record.
public class CsvPreservedRecord<T> : ICsvRecord<T>, IReadOnlyDictionary<CsvFieldIdentifier, ReadOnlyMemory<T>>, IReadOnlyCollection<KeyValuePair<CsvFieldIdentifier, ReadOnlyMemory<T>>>, IEnumerable<KeyValuePair<CsvFieldIdentifier, ReadOnlyMemory<T>>>, IEnumerable where T : unmanaged, IBinaryInteger<T>Type Parameters
- T
- Inheritance
- 
      objectCsvPreservedRecord<T>
- Implements
- 
      ICsvRecord<T>
Constructors
CsvPreservedRecord(in CsvRecord<T>)
Initializes a new instance, copying the record's data.
public CsvPreservedRecord(in CsvRecord<T> record)Parameters
- recordCsvRecord<T>
Properties
FieldCount
Returns the number of fields in the record.
public virtual 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 virtual ReadOnlyMemory<T> this[CsvFieldIdentifier id] { get; }Parameters
- idCsvFieldIdentifier
- Field index of name 
Property Value
- ReadOnlyMemory<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
Line
1-based line number in the CSV data. Empty lines and the header are counted.
public virtual 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 virtual long Position { get; }Property Value
RawRecord
Raw data of the record as a single memory block, not including a possible trailing newline.
public virtual ReadOnlyMemory<T> RawRecord { get; }Property Value
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.
GetField(CsvFieldIdentifier)
Returns the value of the field at the specified index.
public ReadOnlyMemory<T> GetField(CsvFieldIdentifier id)Parameters
- idCsvFieldIdentifier
- Field index of name 
Returns
- ReadOnlyMemory<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
GetField(CsvFieldIdentifier, out int)
Returns the value of the field at the specified index.
protected virtual ReadOnlyMemory<T> GetField(CsvFieldIdentifier id, out int index)Parameters
- idCsvFieldIdentifier
- Field index of name 
- indexint
Returns
- ReadOnlyMemory<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 virtual TValue ParseField<TValue>(CsvConverter<T, TValue> converter, CsvFieldIdentifier id)Parameters
- converterCsvConverter<T, TValue>
- Converter to parse the field with 
- idCsvFieldIdentifier
- Field 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 virtual TValue ParseField<TValue>(CsvFieldIdentifier id)Parameters
- idCsvFieldIdentifier
- Field 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
- typeMapCsvTypeMap<T, TRecord>
Returns
- TRecord
Type Parameters
- TRecord
ToString()
Returns a string that represents the current object.
public override string ToString()Returns
- string
- A string that represents the current object. 
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 
- idCsvFieldIdentifier
- Field index of name 
- valueTValue
- Parsed value, if successful 
Returns
- bool
- trueif the value was successfully parsed
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 virtual bool TryParseField<TValue>(CsvFieldIdentifier id, out TValue value)Parameters
- idCsvFieldIdentifier
- Field index of name 
- valueTValue
- Parsed value, if successful 
Returns
- bool
- trueif the value was successfully parsed
Type Parameters
- TValue
- Value parsed 
Exceptions
- ArgumentException
- The ID points to a field that does not exist 
- CsvConverterMissingException
- Converter not found for - TValue