title: Automapper - set value based on type of object mapped
body: <p>Here's my DTO:</p>
  
  <pre><code>public class DiaryEventType_dto
  {
      public Guid Id { get; set; }
      public string Name { get; set; }
      public string  Group { get; set; }
      public bool Redundant { get; set; }
      public string Type { get; set; }
  }
  </code></pre>
  
  <p>And it maps to two possible entity types:</p>
  
  <pre><code>public partial class UserDiaryEventType
  {
      public System.Guid Id { get; set; }
      public string Name { get; set; }
      public string TypeGroup { get; set; }
      public bool Redundant { get; set; }
  }
  
  public partial class SystemDiaryEventType
  {
      public System.Guid Id { get; set; }
      public string Name { get; set; }
      public string TypeGroup { get; set; }
      public bool Redundant { get; set; }
  }
  </code></pre>
  
  <p>The "Type" property is meant to distinguish which type the DTO was originally mapped from (why would I want to do this rather than have two separate DTO classes? Legacy code, that's why - too much pain to change it all).</p>
  
  <p>Ideally I'd like to populate this during automapping, otherwise the mapper will throw a wobbler at me because "Type" isn't mapped:</p>
  
  <pre><code>        Mapper.CreateMap&lt;Entities.UserDiaryEventType, DiaryEventType_dto&gt;()
              .ForMember(m =&gt; m.Group, o =&gt; o.MapFrom(s =&gt; s.TypeGroup));
          Mapper.CreateMap&lt;DiaryEventType_dto, Entities.UserDiaryEventType&gt;()
              .ForMember(m =&gt; m.TypeGroup, o =&gt; o.MapFrom(s =&gt; s.Group));
          Mapper.CreateMap&lt;Entities.SystemDiaryEventType, DiaryEventType_dto&gt;()
              .ForMember(m =&gt; m.Group, o =&gt; o.MapFrom(s =&gt; s.TypeGroup));
          Mapper.CreateMap&lt;DiaryEventType_dto, Entities.SystemDiaryEventType&gt;()
              .ForMember(m =&gt; m.TypeGroup, o =&gt; o.MapFrom(s =&gt; s.Group));
  </code></pre>
  
  <p>But I can't figure out the syntax for doing so. Something like:</p>
  
  <pre><code>//pseudo code
  Mapper.CreateMap&lt;DiaryEventType_dto, Entities.UserDiaryEventType&gt;()
       .SetValue("User");
  Mapper.CreateMap&lt;DiaryEventType_dto, Entities.SystemDiaryEventType&gt;()
       .SetValue("System");
  </code></pre>
  
  <p>Is it possible?</p>