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
TypeConverterOption
Type converter options.
public abstract MemberMapTypeConverterOption TypeConverterOption { get; }
Property Value
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
objectThe constant value.
Returns
CreateGeneric(Type, MemberInfo)
Creates an instance of MemberMap using the given Type and MemberInfo.
public static MemberMap CreateGeneric(Type classType, MemberInfo member)
Parameters
classType
TypeType of the class the member being mapped belongs to.
member
MemberInfoThe member being mapped.
Returns
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
objectThe default value.
useOnConversionFailure
boolUse default on conversion failure.
Returns
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
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
boolTrue to ignore, otherwise false.
Returns
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
intThe index of the CSV field.
indexEnd
intThe end index used when mapping to an IEnumerable member.
Returns
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
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
intThe index of the name.
Returns
Optional()
Ignore the member when reading if no matching field name can be found.
public virtual MemberMap Optional()
Returns
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
ITypeConverterThe TypeConverter to use.
Returns
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
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
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
ValidatevalidateMessageExpression
ValidateMessage