我的 CSV 文件有一个名为Date
. 此列中的值属于 类型dd/mm/yyyy
。
例如:
08/01/2022
目前我在我的CsvReader
课堂上将它映射到一个string
:
public class CLMExplorerHistory
{
[Name("Date")]
public string Date { get; set; }
}
我已经测试过阅读我的 CSV 文件(显然有更多的信息列):
public void Test2()
{
string strPath = "d:\\Import CLM\\Calendar Simon.csv";
if (!File.Exists(strPath))
return;
try
{
using (var reader = new StreamReader(strPath))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var records = csv.GetRecords<CLMExplorerHistory>();
foreach (var record in records)
{
SimpleLog.Log(record.Date);
}
}
}
catch (System.Exception ex)
{
SimpleLog.Log(ex);
}
}
我检查了日志,一切都很好:
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>01/03/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>08/03/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>15/03/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>22/03/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>29/03/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>05/04/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>12/04/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>19/04/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>26/04/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>03/05/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>10/05/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>17/05/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>24/05/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>31/05/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>07/06/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>14/06/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>21/06/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>28/06/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>05/07/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>12/07/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>19/07/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>26/07/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>02/08/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>09/08/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>16/08/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>23/08/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>30/08/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>06/09/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>13/09/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>20/09/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>27/09/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>04/10/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>11/10/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>18/10/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>25/10/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>01/11/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>08/11/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>15/11/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>22/11/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>29/11/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>06/12/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>13/12/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>20/12/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>27/12/2021</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>03/01/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>10/01/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>17/01/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>24/01/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>31/01/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>07/02/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>14/02/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>21/02/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>28/02/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>07/03/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>14/03/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>21/03/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>28/03/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>04/04/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>18/04/2022</Message>
</LogEntry>
<LogEntry Date="2022-01-08 20:02:08" Severity="Info" Source="MSAToolsLibrary.MSAToolsLibraryClass.Test2" ThreadId="1">
<Message>25/04/2022</Message>
</LogEntry>
我可以向我的属性添加什么属性使其成为DateTime
对象?我不想使用地图,而是使用属性限定符。