I'm not sure if this is just something for which I am not using the correct syntax, or if I lack a concept.
So, the basic design is:
public abstract class ListItemModelBase
{
Guid id { get; set; }
}
public abstract class ListModelBase<T> where T : ListItemModelBase
{
List<T> Items { get; set; }
}
public class OrderListModel : ListModelBase<OrderListItemModel>
{
}
This all works fine, but now I want to add some inheritance for the controllers in my MVC project that use this.
So what I wanted to do is
public interface IListController<T> where T : ListModelBase<ListItemModelBase>
{
T GetList(int Page, int ItemsPerPage);
}
Then I could do:
public class OrderListController : IListController<OrderListModel>, BaseController
{
public OrderListModel GetList(int Page, int ItemsPerPage)
{
}
}
But, obviously, this is not possible due to the fact that a generic type must be applied in ListModelBase.
The goal is to make sure that I can use the IListController interface to mean that I can assume that it controller.GetList(1, 10)will return a ListModelBase to me, and then I can assume that the returned model will have an identifier on each item in the list.
? , ?
:
, , , , .
, , :
public interface IListController<T, TItemModel>
where T : ListModelBase<TListModel>
where TItemModel : ListItemModelBase
{
T GetList(int Page, int ItemsPerPage);
}