C# CSV Parse List Field

In this example, we are going to parse a CSV file that contains a list of values in a single field. Suppose we have the following CSV to parse:


NAME,DATES
ES1 Index,01/01/2023;05/01/2023;12/26/2023
...

Let's create a record class to hold the parsed data first:

public readonly record struct CsvRecord {

    [Name("NAME")]
    public readonly string Name { get; init; }

    [Name("DATES")]
    public IReadOnlyCollection<DateOnly> Dates { get; init; }

}

To parse the CSV field into a collection in C#, we need to create a special class map in CsvHelper: