title: Casting a Type to DBSet<>
body: <p>Is it possible to cast a type definition in C#? Such as the following:</p>
  
  <pre><code>Type t = typeof(Activity) as typeof(System.Data.Entity.DbSet&lt;MyDomain.Activity&gt;)
  </code></pre>
  
  <p>Or trying to force a cast:</p>
  
  <pre><code>Type t2 = typeof(System.Data.Entity.DbSet&lt;MyDomain.Activity&gt;) typeof(Activity);
  </code></pre>
  
  <p>I want to create a type definition <code>System.Data.Entity.DbSet&lt;MyDomain.Activity&gt;</code></p>
  
  <p>I'm doing this because I'm using reflection on my domain, trying to pull on the properties on the context, in case anyone asks.</p>
  
  <pre><code>// get types we are interested in IHit
  var instances = from t in Assembly.GetExecutingAssembly().GetTypes()
                  where t.GetInterfaces().Contains(typeof(IHit))
                           &amp;&amp; t.GetConstructor(Type.EmptyTypes) != null
                  select Activator.CreateInstance(t) as IHit;
  // loop and cast
  foreach (var instance in instances)
  {
      Type t = instance.GetType()
      Type t2 = typeof(System.Data.Entity.DbSet&lt;t&gt;) as typeof(t);
  
      // do something with type 2
  }
  </code></pre>