I have a class structure like this:
public class BaseDataType
{
//... some properties
}
public class FirstCustomDataType : BaseDataType
{
//...some more properties
}
public class SecondCustomDataType : BaseDataType
{
//...some more properties
}
public interface IMonitor<T> where T : BaseDataType
{
List<List<DataSample<T>>> GetData();
}
public abstract class GenericMonitor<T> : IMonitor<T> where T : BaseDataType
{
protected List<List<DataSample<T>>> Data { get; set; }
public List<List<DataSample<T>>> GetData() { return Data; }
}
public class FirstNonGenericMonitor : GenericMonitor<FirstCustomDataType> { }
public class SecondNonGenericMonitor : GenericMonitor<SecondCustomDataType> { }
Now I would like to have a dictionary, that will hold all my non generic monitors:
Dictionary< ResourceToMonitorEnum, IMonitor<BaseDataType> > Monitors
However, I don't know how should I add a new monitor to this dictionary, because this:
Monitors.Add( ResourceToMonitorEnum.Monitor1, new FirstNonGenericMonitor() )
won't let me add new FirstNonGenericMonitor as the IMonitor< T > because the types don't match. I know that it's the type issue but I don't know how to solve it.