我有以下的类
public class EventObject
{
public int OrderID { get; private set; }
public int DemandID { get; private set; }
public string ExternalEventID { get; private set; }
public int Part { get; private set; }
public int BasedOnObjectID { get; private set; }
public int BasedOnStateID { get; private set; }
public DateTime StartDate { get; private set; }
public DateTime EndDate { get; private set; }
public int? EventID { get; private set; }
public static IEnumerable<EventObject> LoadFromCSV(TextReader reader)
{
var plannedEventsToReturn = new List<EventObject>();
var csv = new CsvReader(reader);
csv.Configuration.RegisterClassMap<EventObjectMap >();
return csv.GetRecords<EventObject>().ToList();
}
}
我已经创建了一个映射类,就像在csvHelper中所述。
public sealed class EventObjectMap : CsvClassMap<EventObject>
{
public EventObjectMap ()
{
Map(m => m.OrderID).Index(0);
Map(m => m.DemandID).Index(1);
Map(m => m.ExternalEventID).Index(2);
Map(m => m.Part).Index(3);
Map(m => m.BasedOnObjectID).Index(4);
Map(m => m.BasedOnStateID).Index(5);
Map(m => m.StartDate).Index(6).TypeConverter<OptimizationDateTimeConverter>();
Map(m => m.EndDate).Index(7).TypeConverter<OptimizationDateTimeConverter>();
Map(m => m.EventID).Index(8).TypeConverter<NullableIntConverter>();
}
}
当我到达终点线时
return csv.GetRecords<EventObject>().ToList();
我遇到了一个异常
没有为此类型映射任何属性