title: Using CsvHelper can I translate white space to a nullable?
body: <p>I have some really lame Csv files I need to parse.  I am using CsvHelper and it is working awesome.  Except I have some lines that have whitespace where normaly I have a double.</p>
  
  <p>File:</p>
  
  <blockquote>
    <p>Text,SomeDouble,MoreText </p>
    
    <p>"Good",1.23,"Good" </p>
    
    <p>"Bad", ,"Bad"</p>
  </blockquote>
  
  <p>if I try and map this into</p>
  
  <pre><code>public class Test
  {
    [CsvField(Name = "Text")]
    public string Text { get; set; }
  
    [CsvField(Name = "SomeDouble")]
    public double? SomeDouble{ get; set; }
  
    [CsvField(Name = "MoreText")]
    public string MoreText{ get; set; }
  }
  </code></pre>
  
  <p>then I get an error like this:</p>
  
  <blockquote>
    <p>CsvHelper.CsvReaderException: An error occurred trying to read a
    record of type </p>
    
    <p>Row: '2' (1-based)</p>
    
    <p>Field Index: '1' (0-based) </p>
    
    <p>Field Name: 'SomeDouble'</p>
    
    <p>Field Value: ' '</p>
    
    <p>System.Exception:  is not a valid value for Double. --->
    System.FormatException: Input string was not in a correct format.<br>
    at System.Number.ParseDouble(String value, NumberStyles options,
    NumberFormatInfo numfmt)    at
    System.ComponentModel.DoubleConverter.FromString(String value,
    NumberFormatInfo formatInfo)    at
    System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext
    context, CultureInfo culture, Object value)    --- End of inner
    exception stack trace ---    at
    System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext
    context, CultureInfo culture, Object value)    at
    System.ComponentModel.NullableConverter.ConvertFrom(ITypeDescriptorContext
    context, CultureInfo culture, Object value)    at
    lambda_method(Closure , ICsvReader )    at
    CsvHelper.CsvReader.d__0`1.MoveNext()</p>
  </blockquote>
  
  <p>As I see it, my options are to create a custom parser, or map my value into a string property and do the parsing there.  </p>
  
  <p>Are there any other options?</p>
  
  <p>It would be nice if I could configure that I want to treat white space as null.</p>
  
  <p>As requested, here is a code sample that reproduces the problem</p>
  
  <pre><code> static class Program
      {
          public class Test
          {
              [CsvField(Name = "Text")]
              public string Text { get; set; }
  
              [CsvField(Name = "SomeDouble")]
              public double? SomeDouble { get; set; }
  
              [CsvField(Name = "MoreText")]
              public string MoreText { get; set; }
          }
  
          static void Main(string[] args)
          {
              // create fake in memory file
              var memoryStream = new MemoryStream();
              var streamWriter = new StreamWriter(memoryStream);
              streamWriter.WriteLine("Text,SomeDouble,MoreText");
              streamWriter.WriteLine("Good, 1.23, Good");
              streamWriter.WriteLine("Bad, ,Bad");
  
              streamWriter.Flush();
  
              //reset the file to the begining
              memoryStream.Position = 0;
  
              using (
                  var csv =
                      new CsvReader(
                          new StreamReader(memoryStream)))
              {
                  // this call will blow up with the exception.
                  var records = csv.GetRecords&lt;Test&gt;().ToList();
  
                  //carry on and do stuff with 'records'...
              }
      }
  </code></pre>
  
  <p>Thanks.</p>