title: Maping generic interface to concreate class but using interface definition -> automapper
body: <p>Hey I'm trying to map my generic class to concrete class but using it's interface.</p>
  
  <p>My service returns me data which type is </p>
  
  <blockquote>
    <p>IPaggedResults&lt;Customer></p>
  </blockquote>
  
  <p>and I want to be able to map this to </p>
  
  <blockquote>
    <p>IPaggedResults&lt;CustomerDto></p>
  </blockquote>
  
  <p>It works if I invoke mapping with: </p>
  
  <p><strong>_mapper.Map&lt;PaggedResults&lt;CustomerDto>></strong> </p>
  
  <p>but I want use following syntax: </p>
  
  <p><strong>_mapper.Map&lt;IPaggedResults&lt;CustomerDto>></strong> </p>
  
  <pre><code>public class PaggedResults&lt;T&gt; : IPaggedResults&lt;T&gt;
  {
      public IEnumerable&lt;T&gt; Results { get; protected set; }
      public int TotalResults { get; protected set; }
      public int TotalPages { get; protected set; }
      public int ResultsPerPage { get; protected set; }
  
      public PaggedResults(IEnumerable&lt;T&gt; results, int totalResults, int resultsPerPage)
      {
          Results = results;
          TotalResults = totalResults;
          TotalPages = totalResults / resultsPerPage;
          ResultsPerPage = resultsPerPage;
      }
  }
  
  
  public class CustomerDto
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public string NIP { get; set; }
  }
  </code></pre>
  
  <p>My mapper configuration:</p>
  
  <pre><code>        public static IMapper Initialize()
              =&gt; new MapperConfiguration(cfg =&gt;
              {
                  cfg.CreateMap&lt;CustomerCompany, CustomerDto&gt;();
                  cfg.CreateMap(typeof(IPaggedResults&lt;&gt;), typeof(PaggedResults&lt;&gt;));
                  cfg.CreateMap(typeof(IPaggedResults&lt;&gt;), typeof(IPaggedResults&lt;&gt;)).As(typeof(PaggedResults&lt;&gt;));
              }).CreateMapper();
  </code></pre>
  
  <p>Im'using Automapper by Jimmy Bogard.</p>