title: How to cast to MyInterface<TEntity>
body: <p>I have implemented a generic repository, but have a requirement to dynamically create the appropriate repository at runtime given the entity type as a string.</p>
  
  <p>I have managed to create the repository using:</p>
  
  <pre><code>        Assembly common = Assembly.LoadFrom(@"CommonLibrary.dll");
          Type entityType = common.GetType("Models.OneOfManyEntities");
          Type repoType = typeof(TradeSiftRepository&lt;&gt;).MakeGenericType(entityType);
  
          var repo = Activator.CreateInstance(repoType, new UnitOfWork());
  </code></pre>
  
  <p>However <code>repo</code> is an object and I really want it cast to <code>IRepository&lt;TEntity&gt;</code> I have tried <code>IRepository&lt;entityType&gt;</code> but that is not correct</p>
  
  <p>This is the interface for the repo:</p>
  
  <pre><code>public interface IRepository&lt;TEntity&gt; : IDisposable where TEntity : class
  {
      IQueryable&lt;TEntity&gt; FindAll();
      IQueryable&lt;TEntity&gt; Find(Expression&lt;Func&lt;TEntity, bool&gt;&gt; filter = null, Func&lt;IQueryable&lt;TEntity&gt;, IOrderedQueryable&lt;TEntity&gt;&gt; orderBy = null, string includeProperties = "");
      TEntity FindById(object Id);
      void Insert(TEntity entity);
      void Update(TEntity entity);
      void Delete(object id);
      void Delete(TEntity entity);
  }
  </code></pre>
  
  <p>The activated instance of the repo is of the correct type, but Activator returns a object type so I need to cast it to use the methods.</p>