Open IanKemp opened 3 years ago
RegisterClassMap
has an overload that takes in a map, so you can do this:
var map = new CsvBaseModelClassMap<DerivedFromCsvBaseModel>(CultureInfo.GetCultureInfo("whatever-WHATEVER"));
csv.Context.RegisterClassMap(map);
Hrm, that kinda works, except I don't really want to have to manually instantiate the ClassMap
. I much prefer convention-based mapping, hence this proposal... perhaps I should reword it.
Is there a reason you can't call new? Like do you only know the type at runtime?
Is your feature request related to a problem? Please describe. I have the following class and map defined:
which I'm registering as follows:
Essentially I'm using the
ClassMap.AutoMap()
method to convention-based map all the properties introduced by the derived classes, as well as add the line number.The problem is that
AutoMap()
has 3 overloads, all of which have mandatory parameter(s), butCsvContext.RegisterClassMap()
doesn't allow those parameters to be specified, so there's no way to control what is passed toAutoMap()
. Based on my testing, it does appear that whatever is passed to these overloads is ignored in favour of the options specified for theCsvReader
when constructing it, but even so this is confusing.Describe the solution you'd like
ClassMap.AutoMap()
that delegates to the options specified when constructing the wrapping reader/writer.CsvContext.RegisterClassMap()
that correspond to the current overloads ofClassMap.AutoMap()
, accept mappers with constructors that match those overloads, and make the mapper registration invoke the appropriate constructor. For example: