title: Automapper - Convert string property to SelectList?
body: <p>I'm just starting to learn AutoMapper in an MVC project. I have a base entity "Attendee" with a string field for Gender (possible values of "M" or "F").</p>
  
  <p>I already have a basic mapping created between my Attendee and my AttendeeEditView objects. What I want to do is convert the "M" or "F" Gender string on the model side to a SelectList on the ViewModel side, with the appropriate value selected in the list.</p>
  
  <p>I think I need a ValueResolver to do this... here's what I've written:</p>
  
  <pre><code>public class GenderMenuResolver : ValueResolver&lt;Attendee, SelectList&gt; {
      protected override SelectList ResolveCore( Attendee source ) {
          List&lt;object&gt; items = new List&lt;object&gt;(){
              new{ Value = "F" , Text = "Female" },
              new{ Value = "M" , Text = "Male" }
          };
  
          string Gender = source.Gender ?? "";
          string selectedValue = new List&lt;string&gt;() { "M", "F" }.Contains( Gender.ToUpper() ) ? Gender.ToUpper() : "";
  
          SelectList GenderMenu = new SelectList(
              items,
              "Value",
              "Text",
              selectedValue
          );
  
          return GenderMenu;
      }
  }
  </code></pre>
  
  <p>And my mapping code:</p>
  
  <pre><code>Mapper.CreateMap&lt;Attendee, AttendeeEditView&gt;()
  .ForMember( dest =&gt; dest.Gender, opt =&gt; opt.ResolveUsing&lt;GenderMenuResolver&gt;() );
  
  
  List&lt;AttendeeEditView&gt; ViewModel = Mapper.Map&lt;List&lt;AttendeeEditView&gt;&gt;( Attendees );
  </code></pre>
  
  <p>stepping through I can see this code executes and outputs a proper selectlist. However, I get the following error:</p>
  
  <blockquote>
    <p>Mapping types: SelectList -> SelectList System.Web.Mvc.SelectList ->
    System.Web.Mvc.SelectList</p>
    
    <p>Destination path: List`1[0].Gender.Gender</p>
    
    <p>Source value: System.Web.Mvc.SelectList</p>
  </blockquote>
  
  <p>First, the ".Gender.Gender" mapping seems incorrect.</p>
  
  <p>But what appears to the root issue... an inner exception message reveals this:</p>
  
  <blockquote>
    <p>"Type 'System.Web.Mvc.SelectList' does not have a default constructor"</p>
  </blockquote>
  
  <p>Can anyone help me identify what I'm doing wrong, or perhaps a better approach I should be using? Thanks.</p>