Table of Contents

Class ClassMap

Namespace
CsvHelper.Configuration
Assembly
CsvHelper.dll

Maps class members to CSV fields.

public abstract class ClassMap
Inheritance
ClassMap
Derived
Inherited Members

Properties

ClassType

The type of the class this map is for.

public virtual Type ClassType { get; }

Property Value

Type

MemberMaps

The class member mappings.

public virtual MemberMapCollection MemberMaps { get; }

Property Value

MemberMapCollection

ParameterMaps

The class constructor parameter mappings.

public virtual List<ParameterMap> ParameterMaps { get; }

Property Value

List<ParameterMap>

ReferenceMaps

The class member reference mappings.

public virtual MemberReferenceMapCollection ReferenceMaps { get; }

Property Value

MemberReferenceMapCollection

Methods

ApplyAttributes(MemberMap)

Applies attribute configurations to the map.

protected virtual void ApplyAttributes(MemberMap memberMap)

Parameters

memberMap MemberMap

The member map.

ApplyAttributes(MemberReferenceMap)

Applies attribute configurations to the map.

protected virtual void ApplyAttributes(MemberReferenceMap referenceMap)

Parameters

referenceMap MemberReferenceMap

The member reference map.

ApplyAttributes(ParameterMap)

Applies attribute configurations to the map.

protected virtual void ApplyAttributes(ParameterMap parameterMap)

Parameters

parameterMap ParameterMap

The parameter map.

ApplyAttributes(ParameterReferenceMap)

Applies attribute configurations to the map.

protected virtual void ApplyAttributes(ParameterReferenceMap referenceMap)

Parameters

referenceMap ParameterReferenceMap

The parameter reference map.

AutoMap(CsvConfiguration)

Auto maps all members for the given type. If a member is mapped again it will override the existing map.

public virtual void AutoMap(CsvConfiguration configuration)

Parameters

configuration CsvConfiguration

The configuration.

AutoMap(CsvContext)

Auto maps all members for the given type. If a member is mapped again it will override the existing map.

public virtual void AutoMap(CsvContext context)

Parameters

context CsvContext

The context.

AutoMap(CultureInfo)

Auto maps all members for the given type. If a member is mapped again it will override the existing map.

public virtual void AutoMap(CultureInfo culture)

Parameters

culture CultureInfo

The culture.

AutoMapConstructorParameters(ClassMap, CsvContext, LinkedList<Type>, int)

Auto maps the given map using constructor parameters.

protected virtual void AutoMapConstructorParameters(ClassMap map, CsvContext context, LinkedList<Type> mapParents, int indexStart = 0)

Parameters

map ClassMap

The map.

context CsvContext

The context.

mapParents LinkedList<Type>

The list of parents for the map.

indexStart int

The index starting point.

AutoMapMembers(ClassMap, CsvContext, LinkedList<Type>, int)

Auto maps the given map and checks for circular references as it goes.

protected virtual void AutoMapMembers(ClassMap map, CsvContext context, LinkedList<Type> mapParents, int indexStart = 0)

Parameters

map ClassMap

The map to auto map.

context CsvContext

The context.

mapParents LinkedList<Type>

The list of parents for the map.

indexStart int

The index starting point.

CheckForCircularReference(Type, LinkedList<Type>)

Checks for circular references.

protected virtual bool CheckForCircularReference(Type type, LinkedList<Type> mapParents)

Parameters

type Type

The type to check for.

mapParents LinkedList<Type>

The list of parents to check against.

Returns

bool

A value indicating if a circular reference was found. True if a circular reference was found, otherwise false.

GetGenericType()

Gets the generic type for this class map.

protected virtual Type GetGenericType()

Returns

Type

GetMaxIndex(bool)

Get the largest index for the members and references.

public virtual int GetMaxIndex(bool isParameter = false)

Parameters

isParameter bool

Returns

int

The max index.

Map()

Maps a non-member to a CSV field. This allows for writing data that isn't mapped to a class member.

public virtual MemberMap<object, object> Map()

Returns

MemberMap<object, object>

The member mapping.

Map(Type, MemberInfo, bool)

Maps a member to a CSV field.

public MemberMap Map(Type classType, MemberInfo member, bool useExistingMap = true)

Parameters

classType Type

The type of the class this map is for. This may not be the same type as the member.DeclaringType or the current ClassType due to nested member mappings.

member MemberInfo

The member to map.

useExistingMap bool

If true, an existing map will be used if available. If false, a new map is created for the same member.

Returns

MemberMap

The member mapping.

Parameter(Func<ConstructorInfo>, string)

Maps a constructor parameter to a CSV field.

public virtual ParameterMap Parameter(Func<ConstructorInfo> getConstructor, string name)

Parameters

getConstructor Func<ConstructorInfo>

A function that returns the ConstructorInfo for the constructor.

name string

The name of the constructor parameter.

Returns

ParameterMap

Parameter(ConstructorInfo, ParameterInfo)

Maps a constructor parameter to a CSV field.

public virtual ParameterMap Parameter(ConstructorInfo constructor, ParameterInfo parameter)

Parameters

constructor ConstructorInfo

The ConstructorInfo for the constructor.

parameter ParameterInfo

The ParameterInfo for the constructor parameter.

Returns

ParameterMap

Parameter(string)

Maps a constructor parameter to a CSV field.

public virtual ParameterMap Parameter(string name)

Parameters

name string

The name of the constructor parameter.

Returns

ParameterMap

ReIndex(int)

Resets the indexes based on the given start index.

public virtual int ReIndex(int indexStart = 0)

Parameters

indexStart int

The index start.

Returns

int

The last index + 1.

References(Type, MemberInfo, params object[])

Maps a member to another class map.

public virtual MemberReferenceMap References(Type classMapType, MemberInfo member, params object[] constructorArgs)

Parameters

classMapType Type

The type of the class map.

member MemberInfo

The member.

constructorArgs object[]

Constructor arguments used to create the reference map.

Returns

MemberReferenceMap

The reference mapping for the member.