title: C#: Add conditional generic method (different generic restriction) within generic class
body: <p>I'm trying to add another restriction on a method within a generic class. Is this possible?</p>
  
  <p>Pseudocode:
  <code></p>
  
  <pre><code>public class MyBaseClass&lt;T&gt; where T: class
  {
      public IQueryable&lt;T&gt; ShowThisMethod where T: class, IMyInterface
      {
           // stuff.
      }
  }
  </code></pre>
  
  <p></code></p>
  
  <p>ShowThisMethod should only be available when T is IMyInterface. Also IMyInterface should then give information back (about T) so that I can access properties defined in IMyInterface inside of the method.</p>
  
  <p>Help :)</p>
  
  <p><strong>By the way, this compiles</strong> (and seems "almost right"):</p>
  
  <p><code></p>
  
  <pre><code>public class MyBaseClass&lt;T&gt; where T: class
  {
      public IQueryable&lt;T&gt; ShowThisMethod&lt;T&gt;() where T: class, IMyInterface
      {
          String X = T.MyInterfaceStringProperty;
      }
  }
  </code></pre>
  
  <p></code></p>
  
  <p><strong>More Information about my goal</strong>:</p>
  
  <p>I'm using a generic base class to access a common property (DateTime "Time" property on LINQ object <em>Dinner</em> which is also on <em>Lunch</em>). </p>
  
  <p>Both objects are implementing <strong>ITimeable</strong> which exposes the DateTime property.</p>
  
  <p>In my base class I'd like to have a method Select() which works on IQueryable&amp;ltT> and can automatically filter based on the Time property. Because I'm working off the generic T, the time property is not visible to the base class, unless I tell it that T is implementing <strong>ITimeable</strong>.</p>
  
  <p>I do want the same base class to work for other non-ITimeable objects too, that's why I need the interface restriction on the Select method, and I also need it in order to access the Time property using generics.</p>
  
  <p>Hope that clears the goal :)</p>
  
  <p><strong>P.S. My main concern is not visibility of the method in IntelliSense etc.</strong>. I'd just like to keep my base class working, while being able to access an interface-specified property through generics in it.</p>