Can anyone tell me what am I missing here? Here’s a simple class
That’s a generic class that defines implicit casting operator to it’s generic parameter, no magic here. The code compiles without warning. Methods like this one:
work as well.
What’s even more stunning, whereas this works:
producing error message:
Error 1 Cannot implicitly convert type ‘Mocks.Mock<Mocks.ISomethingUseful>’ to ‘Mocks.ISomethingUseful’. An explicit conversion exists (are you missing a cast?)
Am I missing something here? Why does it say ‘explicit conversion exists’ when I created implicit conversion? Why it doesn’t work for the interface when it works for string?
According to chapter 6.4.4 of C# 3.0 Language specification you just can’t have implicit conversion to an interface. This in yet another time when I hit an invisible wall trying to do something with generics…
And if you thought that
could be a solution: it isn’t – this won’t compile as well.