csvhelper

Using CSVHelper how to deserialise an CSV with a list of Sub Item

∥☆過路亽.° 提交于 2020-08-27 18:48:47
问题 Question: Given to object FooBar that contains a List of Bar , with FooBar and Bar define as such: class FooBar{ int FooID {get;set;} string FooProperty1 {get;set;} List<Bar> Bars {get;set;}; } class Bar{ int BarID {get;set;} string BarProperty1 {get;set;} string BarProperty2 {get;set;} string BarProperty3 {get;set;} } I get the following CSV as input: 1,FooProperty1,BarID_1,BarProperty1_1,BarProperty2_1,BarProperty3_1,BarID_2,BarProperty1_2,BarProperty2_2,BarProperty3_2 Where the field BarID

C# CsvHelper.ValidationException - Why?

戏子无情 提交于 2020-08-07 05:50:49
问题 I am trying to use CSVHelper in C# console app . I have a this exception: CsvHelper.ValidationException: 'Header matching ['Numer Dokumentu'] names at index 0 was not found. And I don't know why becouse this header is on his place in csv file. Here is my Program.cs var packs = new List<Pack>(); using (var streamReader = File.OpenText("C:/.../file.csv")) { var reader = new CsvReader(streamReader); reader.Configuration.RegisterClassMap<PackMap>(); packs = reader.GetRecords<Pack>().ToList(); }

C# CsvHelper.ValidationException - Why?

雨燕双飞 提交于 2020-08-07 05:50:19
问题 I am trying to use CSVHelper in C# console app . I have a this exception: CsvHelper.ValidationException: 'Header matching ['Numer Dokumentu'] names at index 0 was not found. And I don't know why becouse this header is on his place in csv file. Here is my Program.cs var packs = new List<Pack>(); using (var streamReader = File.OpenText("C:/.../file.csv")) { var reader = new CsvReader(streamReader); reader.Configuration.RegisterClassMap<PackMap>(); packs = reader.GetRecords<Pack>().ToList(); }

CsvClassMap not found error in visual studio 2015

牧云@^-^@ 提交于 2020-07-18 05:25:26
问题 I am trying to use CsvHelper library in one of my projects. its just console application. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CsvHelper; using System.IO; using Newtonsoft.Json; using CsvHelper.TypeConversion; namespace csvtest4 { class Program { static void Main(string[] args) { List<string> result = new List<string>(); string value; using (TextReader fileReader = File.OpenText("list.csv")) { var csv = new

Mapping to a Dictionary

情到浓时终转凉″ 提交于 2020-07-09 03:49:45
问题 I was trying to map a csv file so that each record would simply be a Dictionary<string,object> . I am receiving an ArgumentException "Not a member access;" When I try to do this. Code included below: public class CsvFileReader : FileReader { public CsvFileReader(string path) : base(path){ } public IDictionary<string, object> Read() { var reader = new CsvReader(new StreamReader(Path)); reader.Read(); reader.Configuration.RegisterClassMap(new DictionaryClassMap(reader.FieldHeaders)); return