mperdeck / LINQtoCSV

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

Missing columns issue #35

Open cbusuttil opened 9 years ago

cbusuttil commented 9 years ago

First of all I would like to thank you for this library, I have used it in multiple projects.

I don't know if there is a workaround for this issue, but I haven't figured anything out so far. Let's assume we have a csv file with 2 columns, ID and Name. The model will be something like this:-

    [CsvColumn(Name = "ID", FieldIndex = 1, CanBeNull = false)]
    public int UserID { get; set; }

    [CsvColumn(Name = "Name", FieldIndex = 2, CanBeNull = false)]
    public string UserName { get; set; }

If one of those values is left empty, the MissingRequiredFieldException is raised, and the fieldName property is being correct. However if i completely remove a column the fieldName is not being reported correctly. So if i remove the column ID, it will raise the MissingRequiredFieldException but the fieldName missing will be reported as 'Name'. Any idea please? I'm currently checking out the code to see if i can figure this out myself, but in case someone has already found a workaround I would appreciate if he/she can share it :)