Why does this conversion not work?
public interface IMyInterface
{
}
public interface IMyInterface2 : IMyInterface
{
}
public class MyContainer<T> where T : IMyInterface
{
public T MyImpl {get; private set;}
public MyContainer()
{
MyImpl = Create<T>();
}
public static implicit T (MyContainer<T> myContainer)
{
return myContainer.MyImpl;
}
}
When I use my class it causes a compile time error:
IMyInterface2 myImpl = new MyContainer<IMyInterface2>();
Cannot convert from MyContainer<IMyInterface2
> to IMyInterface2...hmmmm