Replies: 1 comment
-
For anyone looking I've found a solution for this. I pass a dictionary in the constructor of my map class public class ResultCSVMap : ClassMap<Result>
{
public ResultCSVMap(Dictionary<int, string> headerTitles)
{
Map(m => m._1).Name(headerTitles[1]);
Map(m => m._2).Name(headerTitles[2]);
Map(m => m._3).Name(headerTitles[3]);
}
} and when registering the class map I pass an instance of the class. var headerTitles = new Dictionary<int, string>();
headerTitles.Add(1, "ThirdCol");
headerTitles.Add(2, "SecondCol");
headerTitles.Add(3, "FirstCol");
using (StreamWriter streamWriter = new StreamWriter(@"C:\\Test.csv", false, Encoding.UTF8))
using (CsvWriter csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture))
{
csvWriter.Context.RegisterClassMap(new ResultCSVMap(headerTitles));
csvWriter.WriteRecords(Results);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Is it possible to create a CSV mapping where the index and header properties of the mapping are set based on another object?
This is the output I'm trying to achieve.
Beta Was this translation helpful? Give feedback.
All reactions