Table of Contents

Class MemberMap

Namespace
CsvHelper.Configuration
Assembly
CsvHelper.dll

Mapping info for a member to a CSV field.

public abstract class MemberMap
Inheritance
MemberMap
Derived
Inherited Members

Constructors

MemberMap()

protected MemberMap()

Properties

Data

Gets the member map data.

public virtual MemberMapData Data { get; protected set; }

Property Value

MemberMapData

TypeConverterOption

Type converter options.

public abstract MemberMapTypeConverterOption TypeConverterOption { get; }

Property Value

MemberMapTypeConverterOption

Methods

Constant(object?)

The constant value that will be used for every record when reading and writing. This value will always be used no matter what other mapping configurations are specified.

public virtual MemberMap Constant(object? constantValue)

Parameters

constantValue object

The constant value.

Returns

MemberMap

CreateGeneric(Type, MemberInfo)

Creates an instance of MemberMap using the given Type and MemberInfo.

public static MemberMap CreateGeneric(Type classType, MemberInfo member)

Parameters

classType Type

Type of the class the member being mapped belongs to.

member MemberInfo

The member being mapped.

Returns

MemberMap

Default(object, bool)

The default value that will be used when reading when the CSV field is empty.

public virtual MemberMap Default(object defaultValue, bool useOnConversionFailure = false)

Parameters

defaultValue object

The default value.

useOnConversionFailure bool

Use default on conversion failure.

Returns

MemberMap

Ignore()

Ignore the member when reading and writing. If this member has already been mapped as a reference member, either by a class map, or by automapping, calling this method will not ignore all the child members down the tree that have already been mapped.

public virtual MemberMap Ignore()

Returns

MemberMap

Ignore(bool)

Ignore the member when reading and writing. If this member has already been mapped as a reference member, either by a class map, or by automapping, calling this method will not ignore all the child members down the tree that have already been mapped.

public virtual MemberMap Ignore(bool ignore)

Parameters

ignore bool

True to ignore, otherwise false.

Returns

MemberMap

Index(int, int)

When reading, is used to get the field at the given index. When writing, the fields will be written in the order of the field indexes.

public virtual MemberMap Index(int index, int indexEnd = -1)

Parameters

index int

The index of the CSV field.

indexEnd int

The end index used when mapping to an IEnumerable member.

Returns

MemberMap

Name(params string[])

When reading, is used to get the field at the index of the name if there was a header specified. It will look for the first name match in the order listed. When writing, sets the name of the field in the header record. The first name will be used.

public virtual MemberMap Name(params string[] names)

Parameters

names string[]

The possible names of the CSV field.

Returns

MemberMap

NameIndex(int)

When reading, is used to get the index of the name used when there are multiple names that are the same.

public virtual MemberMap NameIndex(int index)

Parameters

index int

The index of the name.

Returns

MemberMap

Optional()

Ignore the member when reading if no matching field name can be found.

public virtual MemberMap Optional()

Returns

MemberMap

TypeConverter(ITypeConverter)

Specifies the TypeConverter(ITypeConverter) to use when converting the member to and from a CSV field.

public virtual MemberMap TypeConverter(ITypeConverter typeConverter)

Parameters

typeConverter ITypeConverter

The TypeConverter to use.

Returns

MemberMap

TypeConverter<TConverter>()

Specifies the TypeConverter(ITypeConverter) to use when converting the member to and from a CSV field.

public virtual MemberMap TypeConverter<TConverter>() where TConverter : ITypeConverter

Returns

MemberMap

Type Parameters

TConverter

The Type of the TypeConverter(ITypeConverter) to use.

Validate(Validate)

Specifies an expression to be used to validate a field when reading.

public virtual MemberMap Validate(Validate validateExpression)

Parameters

validateExpression Validate

Returns

MemberMap

Validate(Validate, ValidateMessage)

Specifies an expression to be used to validate a field when reading along with specified exception message.

public virtual MemberMap Validate(Validate validateExpression, ValidateMessage validateMessageExpression)

Parameters

validateExpression Validate
validateMessageExpression ValidateMessage

Returns

MemberMap