title: Pass object from one generic method where T : MyClass to another where T : DerivedClass
body: <p>I have a generic repository which contains this method:</p>
  
  <pre><code>public void Delete&lt;T&gt;(T item) where T : EntityBase
  </code></pre>
  
  <p>I'm trying to add soft-delete behaviour to some objects; ie. when deleted they are not removed from the database, but instead a <code>bool Deleted</code> is set to <code>false</code> and they stop showing up in queries unless a specific parameter is set to include them. In general, the application behaves as if they aren't there, with the exception of the admin views where these items can be restored by flipping that bool back again. My problem is that in passing the object to this method, it's being handled as <code>EntityBase</code>, which doesn't have this soft-delete behaviour because many classes don't need it. <code>SoftDeleteEntityBase</code> extends the <code>EntityBase</code> class to add the soft-delete behaviour, but I can't find a clean way to cast objects so that I can get at the bool. My first thought was this:</p>
  
  <pre><code>public void Delete&lt;T&gt;(T item) where T : EntityBase
  {
      if (item is SoftDeleteEntityBase)
      {
          ((SoftDeleteEntityBase)item).Deleted = true;
          Update&lt;T&gt;(item);
      }
      else
      {
          db.Set&lt;T&gt;().Remove(item);
      }
  }
  </code></pre>
  
  <p>but that gives me the error <code>"Cannot convert type T to SoftDeleteEntityBase"</code>.</p>
  
  <p>How do I get at that bool?</p>