如何将 CsvHelper 配置为忽略与数据行不同的页脚行?
我有一个 CSV 文件,末尾有一个记录计数
id|key|limit
123|1|591
456|2|921
record_count|2
行当我使用类映射通过 CsvHelper
运行此文件时,当它到达 record_count|2
行时,它会抛出异常。我正在通过配置一个 ReadingExceptionOccurred
处理程序来忽略该行来解决这个问题。
csvConfig.ReadingExceptionOccurred = ex =>
{
if (ex.Exception.Context.Parser.RawRecord.Contains("record_count"))
{
return false;
}
return true;
};
这可行,但是是否有更“标准”的方法来处理此页脚记录?
I have a CSV file with a record count row at the end
id|key|limit
123|1|591
456|2|921
record_count|2
When I run this with CsvHelper
using a class map it throws an exception when it gets to the record_count|2
row. I'm working around it by configuring a ReadingExceptionOccurred
handler to ignore that row.
csvConfig.ReadingExceptionOccurred = ex =>
{
if (ex.Exception.Context.Parser.RawRecord.Contains("record_count"))
{
return false;
}
return true;
};
This works but is there is a more "standard" method for handling this footer record?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在配置中使用
ShouldSkipRecord
。You could use
ShouldSkipRecord
in the configuration.