title: In C#, is it possible to determine the type parameter of a generic at runtime?
body: <p>Here's sort of what I have (using Rhino Mocks, but that isn't central to the question):</p>
  
  <pre><code>var entityMock = MockRepository.GenerateMock&lt;IEntity&gt;();
  this.Cache = MockRepository.GenerateStub&lt;Cache&lt;IEntity&gt;&gt;();
  </code></pre>
  
  <p>Is it possible to be more specific in setting the type parameter of <code>Cache&lt;T&gt;</code>? Something like:</p>
  
  <pre><code>var entityMock = MockRepository.GenerateMock&lt;IEntity&gt;();
  this.Cache = MockRepository.GenerateStub&lt;Cache&lt;typeof(entityMock)&gt;&gt;();
  </code></pre>
  
  <p>This doesn't compile of course. But I would like to, if possible, use the type that Rhino Mocks generates, which is a concrete implementation of <code>IEntity</code>.</p>