Here is what I have:
public interface IComponent<TInput> where TInput : Input
{
...
}
public class SpecificComponent : IComponent<SpecificInput>
{
...
}
public class SpecificInput : Input
{
...
}
public class Configuration
{
var Components = new List<IComponent<Input>>();
IComponent<SpecificInput> newComponent = new SpecificComponent();
Components.Add(newComponent);
}
This code will not compile. I get the error message:
Argument 1: cannot convert from 'IComponent<SpecificInput>' to 'IComponent<Input>'
I'm not sure why this is, since SpecificInput inherits from Input, but I assume I am just missing something simple here.
Any ideas?
- EDIT * This is slightly different from Marked duplicate because the solution there does not entirely work for me and the code still creates a compiler warning because it doesn't recognize the inheritance on nested type parameters. That solution doesn't provide for that. And that is the root of my problem. I can't just convert them as shown in that example.