CsvFileRecordLine Class

Definition

Namespace: DataStandardizer.File.CSV

The base type for a CSV data record. Used directly it behaves as a name-keyed bag of field values; subclass it to expose fields as strongly-typed properties.

Syntax

public class CsvFileRecordLine : CsvFileLineBase

Remarks

To expose typed fields, override property getters and setters to call the protected virtual helpers GetPropertyValue<T>([CallerMemberName] string? propertyName = null) and SetPropertyValue<T>(T value, [CallerMemberName] string? propertyName = null). Each helper resolves the backing field name from the property (honouring any CsvFieldAttribute) and reads or writes the field bag inherited from CsvFileLineBase. The resolved field name is cached per line type and property name, so the reflection happens only on first access. These helpers are protected and therefore not part of the public surface; the public Add and the explicit ICsvFileLine members are inherited from CsvFileLineBase.

A value set through SetPropertyValue<T> is stored as an object, so a value-type property, such as an int or a decimal, is boxed when it is set. GetPropertyValue<T> returns the default of T if the field is missing or its value is null, or if the reader called the bad-value handler for the field. It throws an InvalidCastException if the field holds a value of another type. A reader stores the text of a field that no mapping converts, so a property of any type other than string needs a mapping, such as a CsvFieldMappingAttribute, for its value to be read from a file.

CsvFileReader<TRecordLine> requires a CsvFileRecordLine-derived type with a public parameterless constructor; CsvFileWriter<TRecordLine> does not.

Applies to

Targets netstandard1.1, netstandard2.0, netstandard2.1, and net10.0.

See also


This site uses Just the Docs, a documentation theme for Jekyll.