title: Automapper: complex if else statement in ForMember
body: <p>Assuming the <code>Date</code> is a nullable <code>DateTime</code>:</p>
  <pre><code>Mapper.CreateMap&lt;SomeViewModels, SomeDTO&gt;()               
               .ForMember(dest =&gt; dest.Date,
                          opt =&gt; opt.MapFrom(src =&gt;
                          {
                              DateTime? finalDate = null;
                              if (src.HasDate == &quot;N&quot;)
                              {
                                  // so it should be null
                              }
                              else
                              {                                   
                                  endResult = DateTime.Parse(src.Date.ToString());
                                  
                              }                               
                              return finalDate;
  
                          }));
  </code></pre>
  <p>The error I got was:</p>
  <blockquote>
  <p>Error 30  A lambda expression with a statement body cannot be converted
  to an expression tree.</p>
  </blockquote>
  <p>Of course I'm fully aware that I can simplify the query such as:</p>
  <pre><code>Mapper.CreateMap&lt;SomeViewModels, SomeDTO&gt;()
               .ForMember(dest =&gt; dest.Date,
                          opt =&gt; opt.MapFrom(src =&gt; src.HasDate == &quot;N&quot; ? null : DateTime.Parse(src.Date.ToString())));
      
  </code></pre>
  <p>But what if I insist to retain the structure of the first example, because I have more complicated if else statements, that the second example will not able to cater for, or at least will not be very readable?</p>