Search code examples
c#csvcsvhelper

CSVHelper Passing a value to the MapClass


In the source CSV the time but not the date is provided in a field. Is there a way to pass the datetime value to the map class so then we could just combine both using the ConvertUsing?

PseudoCode:

csv.Configuration.RegisterClassMap<RhodesMoClassMap>("DateTime");

public MoClassMap(DateTime date)
{
Map(m => m.TimeLastTick).ConvertUsing(row =>
            {
               var timePart = row.GetField("Time last tick");
               var combined = date + timePart;
               return combinedDateTime;
            });
}

I have seen some questions about this but no examples and the last thread seemed to melt away a few years ago.


Solution

  • csv.Configuration.RegisterClassMap(new RhodesMoClassMap(date));