I can not get around C# covariance for this simple example, here is how I defined my model:
interface IResponse { }
interface ICommand<out TResponse> where TResponse : IResponse { }
class Response : IResponse { }
class Command<TResponse> : ICommand<TResponse> where TResponse : IResponse { }
So I can use it like this
IResponse rsp = new Response(); //Works, obviously!
ICommand<IResponse> cmdi = new Command<Response>(); //Works, but I don't need this
Command<IResponse> cmd = new Command<Response>(); //Compile time error! :(
The Command
in Command<TResponse>
doesn't even has any property or method of TResponse
type. How can I change it so it works?