Pattern for exposing non-generic version of generic interface

后端 未结 3 1936
梦谈多话
梦谈多话 2021-01-31 09:44

Say I have the following interface for exposing a paged list

public interface IPagedList
{
    IEnumerable PageResults { get; }
    int Current         


        
3条回答
  •  长发绾君心
    2021-01-31 10:19

    Define two interfaces, first

        public interface IPageSpecification
        {
            int CurrentPageIndex { get; }
            int TotalRecordCount { get; }
            int TotalPageCount { get; }        
            int PageSize { get; }
        }   
    
    public interface IPagedList : IPageSpecification
    {
        IEnumerable PageResults { get; }
    }   
    

    As you see, IPagedList is derived from IPageSpecification. In your method, only use IPageSpecification as parameter. In other cases, IPagedList - implementers of IPagedList would also contain data from IPageSpecification

提交回复
热议问题