Search code examples
c#csvhelper

CSVHelper Map available fields


Is there a way to map available fields coming from a CSV file ignoring fields that may not be present in the CSV? For example, I have a class with 5 properties. I want to allow mapping from CSV for matching fields ignoring non-matching or fields in the class that are not present in the CSV file.

class CsvRow {
    public string Prop1 { get; set; }
    public string Prop2 { get; set; }
    public string Prop3 { get; set; }
    public string Prop4 { get; set; }
    public string Prop5 { get; set; }
}

CSV file:

Prop1,Prop3
P1,P3

Solution

  • this is probably the answer https://stackoverflow.com/a/67212436/14011696

    [Optional]
    Public string Field {get; set;}