If I have this code:
public interface IThing<T> where T : class
{
// ...
}
public class BaseThing<T> : IThing<T> where T : class
{
// ...
}
public class ThingA : BaseThing<string>
{
// ...
}
public class ThingB : BaseThing<Uri>
{
// ...
}
This code fails:
List<IThing<object>> thingList = new List<IThing<object>>();
thingList.Add(new ThingA());
thingList.Add(new ThingB());
Even though ThingA
(indirectly) inherits from (and should be an instance of) IThing<T>
. Why? Is ThingA
/ThingB
not an instance of IThing<T>
?