title: Casting an object to a generic interface
body: <p>I have the following interface:</p>
  <pre><code>internal interface IRelativeTo&lt;T&gt; where T : IObject
  {
      T getRelativeTo();
      void setRelativeTo(T relativeTo);
  }
  </code></pre>
  <p>and a bunch of classes that (should) implement it, such as:</p>
  <pre><code>public class AdminRateShift : IObject, IRelativeTo&lt;AdminRateShift&gt;
  {
      AdminRateShift getRelativeTo();
      void setRelativeTo(AdminRateShift shift);
  }
  </code></pre>
  <p>I realise that these three are not the same:</p>
  <pre><code>IRelativeTo&lt;&gt;
  IRelativeTo&lt;AdminRateShift&gt;
  IRelativeTo&lt;IObject&gt;
  </code></pre>
  <p>but nonetheless, I need a way to work with all the different classes like AdminRateShift (and FXRateShift, DetRateShift) that should all implement IRelativeTo. Let's say I have a function which returns AdminRateShift as an Object:</p>
  <pre><code>IRelativeTo&lt;IObject&gt; = getObjectThatImplementsRelativeTo(); // returns Object
  </code></pre>
  <p>By programming against the interface, I can do what I need to, but I can't actually cast the Object to IRelativeTo so I can use it.</p>
  <p>It's a trivial example, but I hope it will clarify what I am trying to do.</p>