title: AutoMapper converters fail for null values
body: <p><strong>Note: this question is now out of date and only applies to old versions of AutoMapper. The bug referred to here has been fixed.</strong></p>
  
  <hr>
  
  <p><strong>Problem:</strong></p>
  
  <p>I have an AutoMapper converter that takes a <code>Nullable&lt;bool&gt;</code>/<code>bool?</code> and returns a <code>string</code>. I apply this globally to my profile, and it works for <code>true</code> and <code>false</code> but not for <code>null</code>.</p>
  
  <p><strong>Here is what I have in my AutoMapper profile:</strong></p>
  
  <pre><code>CreateMap&lt;bool?, string&gt;()
      .ConvertUsing&lt;NullableBoolToLabel&gt;();
  </code></pre>
  
  <p><strong>And here is the converter class:</strong></p>
  
  <pre><code>public class NullableBoolToLabel : ITypeConverter&lt;bool?, string&gt;
  {
      public string Convert(bool? source)
      {
          if (source.HasValue)
          {
              if (source.Value)
                  return "Yes";
              else
                  return "No";
          }
          else
              return "(n/a)";
      }
  }
  </code></pre>
  
  <p><strong>Example that demonstrates problem</strong></p>
  
  <pre><code>public class Foo
  {
      public bool? IsFooBarred { get; set; }
  }
  
  public class FooViewModel
  {
      public string IsFooBarred { get; set; }
  }
  
  public class TryIt
  {
      public TryIt()
      {
          Mapper.CreateMap&lt;bool?, string&gt;().ConvertUsing&lt;NullableBoolToLabel&gt;();
          Mapper.CreateMap&lt;Foo, FooViewModel&gt;();
  
          // true (succeeds)
          var foo1 = new Foo { IsFooBarred = true };
          var fooViewModel1 = Mapper.Map&lt;Foo, FooViewModel&gt;(foo1);
          Debug.Print("[{0}]", fooViewModel1.IsFooBarred); // prints: [Yes] 
  
          // false (succeeds)
          var foo2 = new Foo { IsFooBarred = false };
          var fooViewModel2 = Mapper.Map&lt;Foo, FooViewModel&gt;(foo2);
          Debug.Print("[{0}]", fooViewModel2.IsFooBarred); // prints: [No] 
  
          // null (fails)
          var foo3 = new Foo { IsFooBarred = null };
          var fooViewModel3 = Mapper.Map&lt;Foo, FooViewModel&gt;(foo3);
          Debug.Print("[{0}]", fooViewModel3.IsFooBarred); // prints: []
                                                     // should print: [(n/a)]
      }
  }
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Is this a bug or by design?</li>
  <li>If it's by design, what is the reasoning behind it working this way?</li>
  <li>Can you recommend a workaround?</li>
  </ol>