I have a class:
[Serializable]
public class SaveObject
{
public Dictionary<Type, List<BaseModel>> Tables { get; set; }
}
and a method which trying put a new list
public List<T> GetCollection<T>() where T : BaseModel
{
if (saveObject.Tables == null)
saveObject.Tables = new Dictionary<Type, List<BaseModel>>();
List<T> repo = saveObject.Tables.FirstOrDefault(e => e.Key == typeof(T)).Value as List<T>;
if (repo == null)
{
repo = new List<T>();
saveObject.Tables.Add(typeof(T), repo);
}
return repo;
}
The problem is: Cannot convert from 'System.Collections.Generic.List<T>' to 'System.Collections.Generic.List<BaseModel>'
I don't understand why I cannot convert T to Base Model where I note in WHERE that T is BaseModel.