title: Pass Interface Type As Parameter
body: <p>I already know that you can pass an interface as a parameter to a method. This allows you to specify only the relevant members of an object required by a method. What I would like to do is to be able to pass an interface type as a parameter.</p>
  
  <p>Say I declared several interfaces, which were implemented un-evenly across a range of objects that all form a single list/collection. Could I write a helper method which would take both an object from the list and an interface type as a parameter, and check if the object implements the interface? The following code is obviously rubbish, but it illustrates the sort of thing I want to do:</p>
  
  <pre><code>private bool CheckType(object o, interface intrfce)
  {
      try
      {
          object x = (object)(intrfce)o;
          return true;
      }
      catch (InvalidCastException e) 
      {
          return false
      }
  }
  </code></pre>
  
  <p>At the moment I'm simply planning on setting up an enum for the interfaces, and requiring all classes to expose an array/list of interfaces they implement. I can then just check the enum list to see what interfaces they have that are relevant (I'm only interested in the interfaces I have created - I'm not after returning <code>IEnumerable</code> or <code>ICloneable</code> etc.) Or I could write helper methods for each interface. I was just wondering if there was a more elegant way of doing it?</p>