title: implicit operator using interfaces
body: <p>I have a generic class that I'm trying to implement implicit type casting for.  While it mostly works, it won't work for interface casting.  Upon further investigation, I found that there is a compiler error: "User-defined conversion from interface" that applies.  While I understand that this should be enforced in some cases, what I'm trying to do does seem like a legitimate case.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>public class Foo&lt;T&gt; where T : IBar
  {
      private readonly T instance;
  
      public Foo(T instance)
      {
          this.instance = instance;
      }
      public T Instance
      {
          get { return instance; }
      }
      public static implicit operator Foo&lt;T&gt;(T instance)
      {
          return new Foo&lt;T&gt;(instance);
      }
  }
  </code></pre>
  
  <p>Code to use it:</p>
  
  <pre><code>var concreteReferenceToBar = new ConcreteBar();
  IBar intefaceReferenceToBar = concreteReferenceToBar;
  Foo&lt;ConcreteBar&gt; concreteFooFromConcreteBar = concreteReferenceToBar;
  Foo&lt;IBar&gt; fooFromConcreteBar = concreteReferenceToBar;
  Foo&lt;IBar&gt; fooFromInterfaceBar = intefaceReferenceToBar; // doesn't work
  </code></pre>
  
  <p>Does anyone know a workaround, or can anyone explain in a satisfactory way why I shuouldn't be able to cast <code>interfaceReferenceToBar</code> implicitly to <code>Foo&lt;IBar&gt;</code>, since in my case it is not being converted, but only contained within Foo?</p>
  
  <p><strong>EDIT:</strong>
  It looks like covariance might offer salvation.  Let's hope the C# 4.0 specification allows for implicit casting of interface types using covariance.</p>