Skip to content

Commit

Permalink
Handle scenario when record has less values than header
Browse files Browse the repository at this point in the history
(cherry picked from commit 8ed5029)
  • Loading branch information
Tolstovku committed Mar 26, 2024
1 parent 45c81c4 commit 5e2f215
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions CsvHelper.FastDynamic/CsvReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ public static IEnumerable<dynamic> EnumerateDynamicRecords(this CsvReader csvRea

for (var i = 0; i < csvHeader.FieldNames.Length; i++)
{
values[i] = csvReader.Parser[i];
if (i >= csvReader.Parser.Count)
{
values[i] = default;
}
else
{
values[i] = csvReader.Parser[i];
}
}

record = new CsvRecord(csvHeader, values);
Expand Down Expand Up @@ -105,7 +112,14 @@ public static async IAsyncEnumerable<dynamic> EnumerateDynamicRecordsAsync(this

for (var i = 0; i < csvHeader.FieldNames.Length; i++)
{
values[i] = csvReader.Parser[i];
if (i >= csvReader.Parser.Count)
{
values[i] = default;
}
else
{
values[i] = csvReader.Parser[i];
}
}

record = new CsvRecord(csvHeader, values);
Expand Down

0 comments on commit 5e2f215

Please sign in to comment.