我有课:
[Serializable]
public class SaveObject
{
public Dictionary<Type, List<BaseModel>> Tables { get; set; }
}
和尝试放入新列表的方法
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;
}
问题是:
无法从“ System.Collections.Generic.List
我不明白为什么无法将T转换为基本模型,而在这里我注意到T是基本模型。