title: How to get the concrete implementation of an interface by the generic type?
body: <p>I need some help figure out how to use reflection to get the concrete implementation based of the Dto type:</p>
  
  <pre><code>public interface IDocumentService&lt;TDto&gt;
  {
  }
  
  public interface ICommentService: IDoumentService&lt;CommentDto&gt;
  {
  }
  
  public abstract class DocumentService&lt;TEntity,TDto&gt;: IDocumentService&lt;TDto&gt; where TEntity: Entity, where TDto: Dto
  {
  }
  
  public class CommentService: DocumentService&lt;Comment,CommentDto&gt;, ICommentService
  {
  }
  </code></pre>
  
  <p>So, what I want to do, is pass the CommentDto to a method so I can get to the CommentService.</p>
  
  <pre><code>public IDocumentService&lt;TDto&gt; GetDocumentService&lt;TDto&gt;()
  {
      //based on the TDto type I want to find the concrete that 
      //implements IDocumentService&lt;TDto&gt;
  }
  </code></pre>
  
  <p>I would call it like this:</p>
  
  <pre><code>var commentDocumentService = GetDocumentService&lt;CommentDto&gt;();
  </code></pre>
  
  <p>So, I would get back CommentService, knowing that I would only see the methods part of the IDocumentService interface. </p>