Mam sobie metodę generyczną, która działa na ...TCar ... where TCar : ICar, new()
. W metodzie tej tworzę instancję w ten sposób TCar car = new TCar() { ... }
. Ale do tej metody potrzebuję przekazać coś co implementuje ICar. No i tu jest problem, bo taka konstrukcja jak poniżej daje błąd:
public class Car : ICar
{
public Wheel Wheel { get; set; }
}
public interface ICar
{
IWheel Wheel { get; set; }
}
public class Wheel : IWheel
{
}
public interface IWheel
{
}
'Car' does not implement interface member 'ICar.Wheel'. 'Car.Wheel' cannot implement 'ICar.Wheel' because it does not have the matching return type of 'IWheel'.
Wie ktoś jak to rozgryźć?