CsvFieldMappingBuilder Class

Definition

Namespace: DataStandardizer.File.CSV

The concrete fluent field-mapping builder. It implements the ICsvFieldMapping*Builder step interfaces that shape the order in which a single field mapping is configured.

Syntax

public sealed class CsvFieldMappingBuilder<TModel, T>
    : ICsvFieldMappingInitialBuilder<TModel, T>,
      ICsvFieldMappingIdentityNextBuilder<TModel, T>,
      ICsvFieldMappingLogicalNameNextBuilder<TModel, T>,
      ICsvFieldMappingTransformationNextBuilder<TModel>,
      ICsvFieldMappingValidationNextBuilder
    where TModel : class

Remarks

You rarely name this type directly. A pipeline begins at CsvFileMappingBuilder<TModel>.Property<T>, which returns ICsvFieldMappingInitialBuilder<TModel, T>; from there you chain the step methods below. Every step method is implemented as an explicit interface implementation on CsvFieldMappingBuilder<TModel, T>, so each is callable only through the step interface the previous call returned. This is what enforces the allowed call order — for example, once you have set an identity you can no longer set another, and validation follows transformation.

The step interfaces (folded)

The fluent pipeline is defined by a set of small step interfaces, documented here rather than on separate pages:

Step interface Purpose
ICsvFieldMappingInitialBuilder<TModel, in T> The pipeline entry point; aggregates identity, constant, variable, transformation, and optional steps.
ICsvFieldMappingIdentityBuilder<TModel, in T> Sets the field identity (HasFieldName / HasFieldIndex).
ICsvFieldMappingIdentityNextBuilder<TModel, in T> Continuation after an identity is set: field name once read, constant, transformation, variable, or optional.
ICsvFieldMappingLogicalNameBuilder<TModel, in T> Sets the name the field is known by once read (UseFieldName).
ICsvFieldMappingLogicalNameNextBuilder<TModel, in T> Continuation after UseFieldName: constant, transformation, variable, or optional.
ICsvFieldMappingConstantBuilder<in T> Sets a constant field value (HasConstantValue).
ICsvFieldMappingVariableBuilder<in T> Sets a generated field value (HasVariableValue).
ICsvFieldMappingTransformationBuilder<TModel, in T> Attaches a converter (ConvertUsing).
ICsvFieldMappingTransformationNextBuilder<TModel> Continuation after a converter: validation or optional.
ICsvFieldMappingValidationBuilder<TModel> Attaches a validator (ValidateUsing).
ICsvFieldMappingValidationNextBuilder Continuation after validation: optional.
ICsvFieldMappingOptionalBuilder Marks the field optional (IsOptional).

The step methods (explicit on CsvFieldMappingBuilder<TModel, T>)

ConvertUsing is optional for reading the types the reader parses itself, such as the numeric, date, time, bool, Guid and enum types. See converting field values.

Step method Returns Notes
ConvertUsing(CsvFieldConvertFromString<TModel, T> converter) ICsvFieldMappingTransformationNextBuilder<TModel> Sets the deserialization converter (reading). It takes precedence over a TypeConverter and the reader’s built-in parse.
ConvertUsing(CsvFieldConvertToString<TModel> converter) ICsvFieldMappingTransformationNextBuilder<TModel> Sets the serialization converter (writing).
ConvertUsing(Type typeConverterType) ICsvFieldMappingTransformationNextBuilder<TModel> Sets a TypeConverter type. Throws ArgumentException if it is not a TypeConverter. When reading, it takes precedence over the reader’s built-in parse if it converts from a string; otherwise it isn’t used when reading.
ConvertUsing<TConverter>() where TConverter : TypeConverter ICsvFieldMappingTransformationNextBuilder<TModel> Sets a TypeConverter type by type argument.
HasConstantValue(T value) void Sets a constant field value.
HasFieldIndex(int fieldIndex) ICsvFieldMappingIdentityNextBuilder<TModel, T> Maps to a field by index. Throws ArgumentOutOfRangeException if negative.
HasFieldName(string fieldName) ICsvFieldMappingIdentityNextBuilder<TModel, T> Maps to a field by name. Throws ArgumentNullException if null or ArgumentException if all-whitespace.
HasVariableValue(CsvFieldGenerate<T> valueGenerator) void Sets a generated field value.
IsOptional() void Marks the field optional.
UseFieldName(string fieldName) ICsvFieldMappingLogicalNameNextBuilder<TModel, T> Gives the field the name it is known by once read, in place of its name in the file. Required for a name that the header line repeats. Throws ArgumentNullException if null or ArgumentException if all-whitespace. See header lines that repeat a name.
ValidateUsing(CsvFieldValidate<TModel> validator) ICsvFieldMappingValidationNextBuilder Sets a validation delegate.

Constructors

Constructor Notes
CsvFieldMappingBuilder(CsvFieldMapping fieldMapping) Wraps the mapping the step methods populate. Normally created internally by the pipeline.

Methods

Explicit implementation

CsvFieldMappingBuilder<TModel, T> implements the ICsvFieldMapping*Builder step interfaces explicitly; each method is callable only through the step interface that the previous call returned (see The step methods above). (All targets.)

Member Returns
ICsvFieldMappingTransformationBuilder<TModel, T>.ConvertUsing(CsvFieldConvertFromString<TModel, T> converter) ICsvFieldMappingTransformationNextBuilder<TModel>
ICsvFieldMappingTransformationBuilder<TModel, T>.ConvertUsing(CsvFieldConvertToString<TModel> converter) ICsvFieldMappingTransformationNextBuilder<TModel>
ICsvFieldMappingTransformationBuilder<TModel, T>.ConvertUsing(Type typeConverterType) ICsvFieldMappingTransformationNextBuilder<TModel>
ICsvFieldMappingTransformationBuilder<TModel, T>.ConvertUsing<TConverter>() ICsvFieldMappingTransformationNextBuilder<TModel>
ICsvFieldMappingConstantBuilder<T>.HasConstantValue(T value) void
ICsvFieldMappingIdentityBuilder<TModel, T>.HasFieldIndex(int fieldIndex) ICsvFieldMappingIdentityNextBuilder<TModel, T>
ICsvFieldMappingIdentityBuilder<TModel, T>.HasFieldName(string fieldName) ICsvFieldMappingIdentityNextBuilder<TModel, T>
ICsvFieldMappingVariableBuilder<T>.HasVariableValue(CsvFieldGenerate<T> valueGenerator) void
ICsvFieldMappingOptionalBuilder.IsOptional() void
ICsvFieldMappingLogicalNameBuilder<TModel, T>.UseFieldName(string fieldName) ICsvFieldMappingLogicalNameNextBuilder<TModel, T>
ICsvFieldMappingValidationBuilder<TModel>.ValidateUsing(CsvFieldValidate<TModel> validator) ICsvFieldMappingValidationNextBuilder

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.