У меня есть список словаря с тем же списком ключей, но с другим значением. Есть ли способ записать это в файл CSV с помощью CSVHelper? У меня есть пример кода ниже, но он явно не сработал.
static void Main(string[] args)
{
List records = new List();
Dictionary data1 = new Dictionary();
data1.Add("Name1", "Value1");
data1.Add("Name2", "Value2");
records.Add(data1);
Dictionary data2 = new Dictionary();
data2.Add("Name1", "Value1");
data2.Add("Name2", "Value2");
records.Add(data2);
using (var writer = new StreamWriter("e:\\temp\\test.csv"))
using (var csv = new CsvWriter(writer))
{
csv.WriteRecords(records);
//GEtting exception here
//CsvHelper.Configuration.CsvConfigurationException: 'Types that inherit IEnumerable cannot be auto mapped. Did you accidentally call GetRecord or WriteRecord which acts on a single record instead of calling GetRecords or WriteRecords which acts on a list of records?'
}
}
У меня есть список словаря с тем же списком ключей, но с другим значением. Есть ли способ записать это в файл CSV с помощью CSVHelper? У меня есть пример кода ниже, но он явно не сработал. [code] static void Main(string[] args) {
List records = new List(); Dictionary data1 = new Dictionary(); data1.Add("Name1", "Value1"); data1.Add("Name2", "Value2"); records.Add(data1);
Dictionary data2 = new Dictionary(); data2.Add("Name1", "Value1"); data2.Add("Name2", "Value2"); records.Add(data2);
using (var writer = new StreamWriter("e:\\temp\\test.csv")) using (var csv = new CsvWriter(writer)) {
csv.WriteRecords(records); //GEtting exception here //CsvHelper.Configuration.CsvConfigurationException: 'Types that inherit IEnumerable cannot be auto mapped. Did you accidentally call GetRecord or WriteRecord which acts on a single record instead of calling GetRecords or WriteRecords which acts on a list of records?'