I am working with CsvHelper and being able to parse csv file. My question is how can I parse the Date into DateTime object
I want to convert it via CsvHelper while it is parsing the csv rather than iterating the collection
public static List<StockModel> SplitCsv(string csv) { var textReader = new StringReader(csv); var csvr = new CsvReader(textReader); csvr.Configuration.RegisterClassMap<ModelMap>(); var records = csvr.GetRecords<StockModel>().ToList(); return records; } public class StockModel { public string Date { get; set; } // I want this object to be DateTime public string Base { get; set; } public string Open { get; set; } } public sealed class ModelMap : CsvClassMap<StockModel> { public ModelMap() { Map(m => m.Date); Map(m => m.Base); Map(m => m.Open); } } CSV example
Date,Base,Open 2016-02-29,1437.530029,1445.839966 2016-02-25,1431.439941,1431.439941 2016-02-24,1430.459961,1432.430054