I was wondering if I am doing this right, but I am using CsvHelper and have the following fluent class maps defined:
internal class WasteEstimationGenericDayCsvMap : CsvClassMap<WasteEstimationGenericDay>
{
public WasteEstimationGenericDayCsvMap(WasteEstimationGenericDay dayModel)
{
var qualityModel = dayModel.Quality;
ConstructUsing(() => new WasteEstimationGenericDay(dayModel.ModelUnitContext));
Map(m => m.InflowVolume).Name(dayModel.GetPropertyDisplayName(() => dayModel.InflowVolume));
References<WasteStreamQualityCsvMap>(m => m.Quality, qualityModel);
}
}
internal class WasteStreamQualityCsvMap : CsvClassMap<WasteStreamQuality>
{
public WasteStreamQualityCsvMap(WasteStreamQuality qualityModel)
{
ConstructUsing(() => new WasteStreamQuality(qualityModel.ModelUnitContext));
Map(m => m.TotalNitrogen).Name(qualityModel.GetPropertyDisplayName(() => qualityModel.TotalNitrogen));
Map(m => m.TotalPhosphorus).Name(qualityModel.GetPropertyDisplayName(() => qualityModel.TotalPhosphorus));
Map(m => m.TotalDissolvedSalts).Name(qualityModel.GetPropertyDisplayName(() => qualityModel.TotalDissolvedSalts));
Map(m => m.VolatileSolids).Name(qualityModel.GetPropertyDisplayName(() => qualityModel.VolatileSolids));
Map(m => m.TotalSolids).Name(qualityModel.GetPropertyDisplayName(() => qualityModel.TotalSolids));
Map(m => m.ElectricalConductivity).Name(qualityModel.GetPropertyDisplayName(() => qualityModel.ElectricalConductivity));
}
}
These class maps are designed to be able to map dynamic column names in no particular order to my type WasteEstimationGenericDay
, however the problem is before mapping values to the type I need to specify the units those values are in, this is why ConstructUsing()
is specified in each class map to set the units during the construction of the type for mapping.
However for the referenced class map for the type WasteStreamQuality
on the property WasteEstimationGenericDay.Quality, the
ConstructUsing()` statement is never called and the units are not specified. Does anyone know if I am doing something wrong in my mapping configuration? or is this a bug/limitation in CsvHelper?
I have also tried registering both class maps separately on the configuration like so:
csvReaderConfig.RegisterClassMap(new WasteEstimationGenericDayCsvMap(dayModel));
csvReaderConfig.RegisterClassMap(new WasteStreamQualityCsvMap(dayModel.Quality));
But it does not appear to have any affect unless it is the type that was specified when calling CsvReader.GetRecords<T>()
.
Thanks for any help.
After also posting this question as an issue I got the following response:
Taking a quick look at the source (as I don't have a computer to test it on at the moment), it looks like that isn't implemented, but should be a pretty quick thing to do.