Using choETL I found that I can map csv position to property name like this
public class Emp
{
public string Name { get; set; }
public string Other{ get; set; }
public string MyId { get; set; }
}
[Test]
public void TestMapping()
{
ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration();
config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("MyId", 1));
config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2));
config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Other", 3));
config.WithFirstLineHeader(true);
string csv = @"Id, Name,
1, Tom, NY
2, Mark, NJ
3, Lou, FL
4, Smith, PA
5, Raj, DC
";
using (var p = ChoCSVReader<Emp>.LoadText(csv, Encoding.ASCII,config)
// .WithFirstLineHeader(true)
)
{
Console.WriteLine(p.ToList().DumpAsJson());
}
}
However what I really want is to be able to map at runtime. Using the following pseudo code:
config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("MyId", "Id"));
config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", "Name"));
config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Other", "City"));
string csv1 = @"Id, Name, City
1, Tom, NY
2, Mark, NJ
3, Lou, FL
4, Smith, PA
5, Raj, DC
";
string csv2 = @"Name, Id, City
Tom, 1, NY
Mark, 2, NJ
Lou, 3, FL
Smith, 4, PA
Raj, 5, DC
";
So I can use the same configuration for both csv file. They are almost identical except that the position has been swapped. Is this possible with choETL?