So I got a collection of type Item
and I'm trying to map the values to a CSV file but it's not working properly.. It maps these values just fine.. ItemName
SubTitle
Price
Condition
Quantity
QuantitySold
ProductImage
and then it doesn't map any more.
I think this is because the other two properties are collections.. List
and Dictionary
This is how I am currently mapping it.
using (var mem = new MemoryStream())
using (var writer = new StreamWriter(mem))
using (var csvWriter = new CsvWriter(writer, CultureInfo.CurrentCulture))
{
csvWriter.Configuration.Delimiter = ",";
csvWriter.Configuration.HasHeaderRecord = true;
csvWriter.Configuration.AutoMap<Item>();
csvWriter.WriteHeader<Item>();
csvWriter.WriteRecords(Products);
writer.Flush();
var result = Encoding.UTF8.GetString(mem.ToArray());
File.WriteAllText("Items.csv", result);
Console.WriteLine(result);
}
And here is the model
class Item
{
public string ItemName { get; set; }
public string SubTitle { get; set; }
public string Price { get; set; }
public string Condition { get; set; }
public Dictionary<string, List<string>> SKU { get; set; }
public string Quantity { get; set; }
public string QuantitySold { get; set; }
public string ProductImage { get; set; }
public List<string> ProductImages { get; set; }
}