title: Conditionally mapping one source type to two destination types
body: <p>I have a source DTO like this </p>
  
  <pre><code>public class Member 
  {
      public string MemberId {get;set;}
      public string MemberType {get;set;}
      public string Name {get;set;}
  }
  </code></pre>
  
  <p>The member type can be "Person" or "Company".</p>
  
  <p>And two destination classes like this </p>
  
  <pre><code>public class PersonMember 
  {
      public int PersonMemberId {get;set;}
      public string Name {get;set;}
  }
  
  public class CompanyMember 
  {
      public int CompanyMemberId {get;set;}
      public string Name {get;set;}
  }
  </code></pre>
  
  <p>I want to use Automapper to check what the value of MemberType is in the source class and depending on that type, map to one of the two destination types. </p>
  
  <p>I saw the example of <a href="https://github.com/AutoMapper/AutoMapper/wiki/Conditional-mapping" rel="nofollow">conditionally mapping</a>, but it maps the field it performs the conditional check on. I want to check the condition and map a different field.</p>
  
  <pre><code>var config = new MapperConfiguration(cfg =&gt; {
    cfg.CreateMap&lt;Foo,Bar&gt;()
      .ForMember(dest =&gt; dest.baz, opt =&gt; opt.Condition(src =&gt; (src.baz &gt;= 0))); 
  });
  </code></pre>
  
  <p>My goal is something like this - </p>
  
  <pre><code>cfg.CreateMap&lt;Member, PersonMember&gt;()
  .ForMember(dest =&gt; PersonMember.PersonMemberId, opt =&gt; if the source.MemberType == "Person" perform mapping from MemberId, otherwise do nothing);
  
  cfg.CreateMap&lt;Member, CompanyMember&gt;()
  .ForMember(dest =&gt; CompanyMember.CompanyMemberId, opt =&gt; if the source.MemberType == "Company" perform mapping from MemberId, otherwise do nothing);
  </code></pre>