How to correct this design. Error because C# doesn't allow Type Covariance. How can I improve or correct this design
public interface ITimeEvent
{
}
public interface IJobTimeEvent : ITimeEvent
{
}
public interface IActivityTimeEvent : ITimeEvent
{
}
public interface IAssignmentTimeEvent<T> where T : ITimeEvent
{
T ParentTimeEvent
{
get;
set;
}
}
public class ScheduleJobTimeEvent : IAssignmentTimeEvent<IJobTimeEvent>
{
public IJobTimeEvent ParentTimeEvent
{
get;
set;
}
}
public class ScheduleActivityTimeEvent : IAssignmentTimeEvent<IActivityTimeEvent>
{
public IActivityTimeEvent ParentTimeEvent
{
get;
set;
}
}
List<IAssignmentTimeEvent<ITimeEvent>> lst = new List<IAssignmentTimeEvent<ITimeEvent>>();
lst.Add(new ScheduleJobTimeEvent()); //Error because C# doesn't allow Type Covariance
lst.Add(new ScheduleActivityTimeEvent()); //Error because C# doesn't allow Type Covariance