简体   繁体   中英

Using FileHelpers to read CSV by column name instead of position

Given the following record definition

[DelimitedRecord(",")]
public class Line
{
    public string FirstName;

    public string LastName;
}

And the following code to import the CSV

var engine = new FileHelperEngine<Line>();
// Ignore header line
engine.Options.IgnoreFirstLines = 1;
var records = engine.ReadFileAsList(csvFile);

I would like to be able to read both of these CSV files with the same result.

CSV in same order as record definition

FirstName,LastName
John,Doe

CSV with different order, with same header names however

LastName,FirstName
Doe,John

The current version of the library don't support that feature

Is on the pending list for the next big release

https://github.com/MarcosMeli/FileHelpers/issues/122

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM