I'm working with some complex generics to allow inheritance from root class with state information and I don't quite understand two different scenarios (from my perspective it's the same, but probably I'm wrong):
Why this is ok:
class Client
{
public interface IState { }
protected class State : IState { }
class States<T> where T : IState
{
public States(T state) { }
}
public Client()
{
State state = new State();
States<IState> states = new States<IState>(state);
}
}
But this is not:
class Client<T> where T : Client<T>.IState
{
public interface IState { }
protected class State : IState { }
class States
{
public States(T state) { }
}
public Client()
{
State state = new State();
States states = new States(state); //Error -> Can't convert Client<T>.State to T
}
}