r.straughan
r.straughan

Reputation: 141

How to skip blank rows in CsvHelper >28.0.0?

CsvHelper 28.0.0 changes the ShouldSkipRecordArgs from a property string[] Record to IReaderRow Row. Although this interface exposes a this property, it does not implement IEnumerable.

Previously you could configure the CsvReader to skip blank rows by using ShouldSkipRecord = x => x.Record.All(field => string.IsNullOrWhiteSpace(field)). This is now no longer possible.

What is the recommended approach to skip blank rows as of 28.0.0?

Regards, Rob.

Upvotes: 5

Views: 1465

Answers (1)

r.straughan
r.straughan

Reputation: 141

Just found the commit where this change was made, thankfully the unit tests show the update. The string[] Record property does still exist you just have to navigate to it.

Change:

ShouldSkipRecord = x => x.Record.All(field => string.IsNullOrWhiteSpace(field))

To:

ShouldSkipRecord = x => x.Row.Parser.Record?.All(field => string.IsNullOrWhiteSpace(field)) ?? false

Upvotes: 9

Related Questions