mperdeck / LINQtoCSV

Popular, easy to use library to read and write CSV files.
199 stars 112 forks source link

Mixing FieldIndex and Name to read a dynamic column name #38

Open kowsheek opened 9 years ago

kowsheek commented 9 years ago

I'm trying to read in a class such as the following where one/or more of the property names are available at runtime.

public class BreakdownCSV
{
      [CsvColumn(FieldIndex = 1)]
      public string BreakdownProperty { get; set; }
      [CsvColumn(Name = "Day of Week Name")]
      public DayOfWeek DayOfWeekName { get; set; }
      [CsvColumn(Name = "SessionName")]
      public string SessionName { get; set; }
}

but the BreakdownProperty value is coming up as null. As far as I understand, this is because the reader isn't able to read properties without the matching the property's name or it being specified in the attribute.

How would I go about doing this?