title: Using csvHelper to read cell content into List or Array
body: <p>I have a csv file of the type:</p>
  
  <pre><code>name,numbersA,numbersB
  Bob,"1,2,3,4","6,7,8,9"
  Brabra,"9,3","4,8,5,7,2"
  </code></pre>
  
  <p>So arrays of ints are given by the numbers in between the " ".</p>
  
  <p>I want to map that to the following class</p>
  
  <pre><code>    public class Names
      {
          [Name("name")]
          public string Name { get; set; }
  
          [Name("numbersA")]
          public List&lt;int&gt; NumbersA{ get; set; }
  
          [Name("numbersB")]
          public List&lt;int&gt; NumbersB{ get; set; }
  
      }
  </code></pre>
  
  <p>I don't specifically mind if the NumbersA/B is of type int[] or List. So far I managed to read the data by specifying the type of NumbersA/B as string and that works correctly (I get the string between the " "). Can this be done automatically in csvHelper or do I have to parse the string myself later on.</p>
  
  <pre><code>void Main()
  {
      using (var reader = new StreamReader("path\\to\\file.csv"))
      using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
      {
          var records = csv.GetRecords&lt;Names&gt;();
          List&lt;Names&gt; NameList = records.ToList();
      }
  }
  </code></pre>
  
  <p>Any help would be very much appreciated.</p>
  
  <h1>SOLUTION</h1>
  
  <p>Credit goes to @Oguz Ozgul (see below). I made a couple of minor changes.</p>
  
  <pre><code>
  public class Names
  {
      [Name("name")]
      public string Name { get; set; }
  
      [Name("numbersA")]
      [TypeConverter(typeof(ToIntArrayConverter))]
      public List&lt;int&gt; NumbersA{ get; set; }
  
      [Name("numbersB")]
      [TypeConverter(typeof(ToIntArrayConverter))]
      public List&lt;int&gt; NumbersB{ get; set; }
  
  }
  
  public class ToIntArrayConverter : TypeConverter
  {
      public override object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData)
      {
          if (text == "") return new List&lt;int&gt;();
          string[] allElements = text.Split(',');
          int[] elementsAsInteger = allElements.Select(s =&gt; int.Parse(s)).ToArray();
          return new List&lt;int&gt;(elementsAsInteger);
      }
  
      public override string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData)
      {
          return string.Join(",", ((List&lt;int&gt;)value).ToArray());
      }
  }
  
  </code></pre>