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
MemberMaps
The class member mappings.
public virtual MemberMapCollection MemberMaps { get; }
Property Value
ParameterMaps
The class constructor parameter mappings.
public virtual List<ParameterMap> ParameterMaps { get; }
Property Value
ReferenceMaps
The class member reference mappings.
public virtual MemberReferenceMapCollection ReferenceMaps { get; }
Property Value
Methods
ApplyAttributes(MemberMap)
Applies attribute configurations to the map.
protected virtual void ApplyAttributes(MemberMap memberMap)
Parameters
memberMap
MemberMapThe member map.
ApplyAttributes(MemberReferenceMap)
Applies attribute configurations to the map.
protected virtual void ApplyAttributes(MemberReferenceMap referenceMap)
Parameters
referenceMap
MemberReferenceMapThe member reference map.
ApplyAttributes(ParameterMap)
Applies attribute configurations to the map.
protected virtual void ApplyAttributes(ParameterMap parameterMap)
Parameters
parameterMap
ParameterMapThe parameter map.
ApplyAttributes(ParameterReferenceMap)
Applies attribute configurations to the map.
protected virtual void ApplyAttributes(ParameterReferenceMap referenceMap)
Parameters
referenceMap
ParameterReferenceMapThe 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
CsvConfigurationThe 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
CsvContextThe 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
CultureInfoThe 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
ClassMapThe map.
context
CsvContextThe context.
mapParents
LinkedList<Type>The list of parents for the map.
indexStart
intThe 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
ClassMapThe map to auto map.
context
CsvContextThe context.
mapParents
LinkedList<Type>The list of parents for the map.
indexStart
intThe index starting point.
CheckForCircularReference(Type, LinkedList<Type>)
Checks for circular references.
protected virtual bool CheckForCircularReference(Type type, LinkedList<Type> mapParents)
Parameters
type
TypeThe 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
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
Map(Type, MemberInfo, bool)
Maps a member to a CSV field.
public MemberMap Map(Type classType, MemberInfo member, bool useExistingMap = true)
Parameters
classType
TypeThe 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
MemberInfoThe member to map.
useExistingMap
boolIf 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
stringThe name of the constructor parameter.
Returns
Parameter(ConstructorInfo, ParameterInfo)
Maps a constructor parameter to a CSV field.
public virtual ParameterMap Parameter(ConstructorInfo constructor, ParameterInfo parameter)
Parameters
constructor
ConstructorInfoThe ConstructorInfo for the constructor.
parameter
ParameterInfoThe ParameterInfo for the constructor parameter.
Returns
Parameter(string)
Maps a constructor parameter to a CSV field.
public virtual ParameterMap Parameter(string name)
Parameters
name
stringThe name of the constructor parameter.
Returns
ReIndex(int)
Resets the indexes based on the given start index.
public virtual int ReIndex(int indexStart = 0)
Parameters
indexStart
intThe 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
TypeThe type of the class map.
member
MemberInfoThe member.
constructorArgs
object[]Constructor arguments used to create the reference map.
Returns
- MemberReferenceMap
The reference mapping for the member.