title: How to create generic mapping with AutoMapper and ConstructUsing
body: <p>I have a map configuration:</p>
  
  <pre><code>Mapper.Initialize(cfg =&gt;
  {
      cfg.CreateMap&lt;IDictionary&lt;int, MyType1&gt;, List&lt;MyType1&gt;&gt;().ConstructUsing(
          x0 =&gt; x0?.OrderBy(x =&gt; x.Key).Select(x =&gt; x.Value).ToList());
  });
  </code></pre>
  
  <p>How can I change this to work with "all MyTypes"? </p>
  
  <p>I want to convert from <code>IDictionary&lt;int, T&gt;</code> to <code>List&lt;T&gt;</code> for any T type.</p>
  
  <p>I found a very ugly solution:</p>
  
  <pre><code>cfg.CreateMap(typeof(IDictionary&lt;,&gt;), typeof(List&lt;&gt;)).ConstructUsing(
      x0 =&gt;
      {
          if (x0 == null)
          {
              return null;
          }
  
          var dict = (IEnumerable)x0;
          var type = x0.GetType().GetGenericArguments()[1];
          var list = (IList)Activator.CreateInstance(typeof(List&lt;&gt;).MakeGenericType(type));
          CastDictionaryEntry(dict).OrderBy(x =&gt; x.Key).ForEach(x =&gt; list.Add(x.Value));
          return list;
      }
  );
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>static IEnumerable&lt;DictionaryEntry&gt; CastDictionaryEntry(IEnumerable dict)
  {
      foreach (var item in dict)
      {
          yield return (DictionaryEntry)item;
      }
  }
  </code></pre>
  
  <p>Is there any easier way to do this?</p>