title: Automapper. Map if source member is null
body: <p>I have two classes and map one to other with Automapper. For instance:</p>
  
  <pre><code>public class Source 
  {
      // IdName is a simple class containing two fields: Id (int) and Name (string)
      public IdName Type { get; set; } 
  
      public int TypeId {get; set; }
  
      // another members
  }
  
  public class Destination
  {
      // IdNameDest is a simple class such as IdName
      public IdNameDest Type { get; set; } 
  
      // another members
  }
  </code></pre>
  
  <p>Then I use Automapper to map <code>Source</code>  to <code>Destination</code>:</p>
  
  <pre><code>cfg.CreateMap&lt;Source, Destination&gt;();
  </code></pre>
  
  <p>It works properly but sometimes member <code>Type</code> in class <code>Source</code> becomes <code>null</code>. In these cases I would like to map member <code>Type</code> in class <code>Destination</code> from <code>TypeId</code> property. That's what I want in a nutshel: </p>
  
  <pre><code>if Source.Type != null 
  then map Destination.Type from it
  else map it as 
      Destination.Type = new IdNameDest { Id = Source.Id }
  </code></pre>
  
  <p>Is it possible with AutoMapper? </p>