title: Switching on type with a generic return type
body: <p>I'm working on making EF easier to unit test by writing some helpers that will make properties for me.  I have a couple of backing fields</p>
  
  <pre><code>private Mock&lt;DbSet&lt;Workflow&gt;&gt; mockedWorkFlows;
  private Mock&lt;DbSet&lt;WorkflowError&gt;&gt; mockedWorkFlowErrors;
  </code></pre>
  
  <p>And I want a generic function to be able to return me the correct backing field with the following function </p>
  
  <pre><code>public Mock&lt;DbSet&lt;T&gt;&gt; Mocked&lt;T&gt;(T t) where T : class
  {
     if ( (object)t is Workflow)
     {
         return mockedWorkFlows; //cannot Workflow to T
      }
  }
  </code></pre>
  
  <p>There are several private backing fields which I want to be returned based on the type passed it.  </p>
  
  <p>However, even if I add a class constraint of <code>Workflow</code>, I get the same error.</p>
  
  <p>I also tried switching on <code>t's</code> type but no luck there either.  The types of the several backing fields do not share a common ancestor, other than object.  Is what I'm trying to do possible?</p>