SuperDave
SuperDave

Reputation: 413

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.

Upvotes: 2

Views: 1064

Answers (1)

David Specht
David Specht

Reputation: 9074

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

Upvotes: 5

Related Questions