title: Automapper empty list to empty list
body: <p>I have the following two classes:</p>
  
  <p>I have two classes</p>
  
  <pre><code> public class SourceClass
  {
      public Guid Id { get; set; }
      public string Provider { get; set; }
  }
  
  
  public class DestinationClass
  {
      public Guid Id { get; set; }
      public List&lt;string&gt; Providers { get; set; }
  }
  </code></pre>
  
  <p>I have the following mappings for my automapper</p>
  
  <pre><code>CreateMap&lt;SourceClass, DestinationClass&gt;()
    .ForMember(destinationMember =&gt; destinationMember.Providers,
    memberOptions =&gt; memberOptions.MapFrom(src =&gt; new List&lt;string&gt; {src.Provider ?? ""}));
  
  CreateMap&lt;DestinationClass, SourceClass&gt;().ForMember(SourceClass =&gt; SourceClass.Provider,
                  memberOptions =&gt; memberOptions.MapFrom(src =&gt; src.Providers.FirstOrDefault()));
  </code></pre>
  
  <p>I wrote some unit tests and can confirm the following behaviour:</p>
  
  <p>When Providers in my destination class is null, it maps to null, which is great. However, I'd like to change my mapping so that if Providers is an empty list, it maps to an empty list and similarly, if Provider is null, I'd want it to map to an empty list instead of a list with an empty string.</p>
  
  <p>Does anyone know how I can go about doing this? I've tried this for my mapping from SourceClass to DestinationClass:</p>
  
  <pre><code>CreateMap&lt;SourceClass, DestinationClass&gt;()
        .ForMember(destinationMember =&gt; destinationMember.Providers,
  memberOptions =&gt; memberOptions.MapFrom(src =&gt; !string.IsNullOrEmpty(src.Provider) ? new List&lt;string&gt; {src.Provider} : new List&lt;string&gt;()));
  </code></pre>
  
  <p>but for going the other way, an empty list is mapping to null, instead of an empty list. (I think because of FirstOrDefault() ). Does anyone know how I can work around this?</p>