title: Why I cannot cast derived generic type to base non-generic type (through a constrain)?
body: <p>Given this fictional example:</p>
  
  <pre><code>class NonGeneric
  {
  }
  
  class Generic&lt;T&gt; : NonGeneric
      where T : NonGeneric
  {
      T DoSomething()
      {
          return this; // **
      }
  }
  </code></pre>
  
  <p>I'd expect it compiles: <code>Generic&lt;T&gt;</code> derives from <code>NonGeneric</code> and <code>T</code> must be a derived class so it satisfies its constrain. </p>
  
  <p>I should be able to do this:</p>
  
  <pre><code>NonGeneric obj = new Generic&lt;NonGeneric&gt;();
  </code></pre>
  
  <p>Then there should be no problem in this instruction:</p>
  
  <pre><code>return this;
  </code></pre>
  
  <p>Or at least this:</p>
  
  <pre><code>return (T)this;
  </code></pre>
  
  <p>Unfortunately it doesn't work and above example doesn't compile with error:</p>
  
  <blockquote>
    <p>Cannot convert type <code>NonGeneric&lt;T&gt;</code> to '<code>T</code>'</p>
  </blockquote>
  
  <p>I'm doing something wrong, and I can't see it, or it's just not allowed? Why this?</p>
  
  <hr/>
  
  <p>I would avoid, if possible, any workaround like the one I describe <a href="https://stackoverflow.com/a/13992747/1207195">in this post</a> (Reflection, dynamic compiled methods and so on). I would avoid <code>dynamic</code> objects too (design decision, I can't change that).</p>