Say I have the following interface for exposing a paged list
public interface IPagedList
{
IEnumerable PageResults { get; }
int Current
My approach here would be to use new
to re-declare the PageResults
, and expose the T
as a Type
:
public interface IPagedList
{
int CurrentPageIndex { get; }
int TotalRecordCount { get; }
int TotalPageCount { get; }
int PageSize { get; }
Type ElementType { get; }
IEnumerable PageResults { get; }
}
public interface IPagedList<T> : IPagedList
{
new IEnumerable<T> PageResults { get; }
}
This will, however, require "explicit interface implementation", i.e.
class Foo : IPagedList<Bar>
{
/* skipped : IPagedList<Bar> implementation */
IEnumerable IPagedList.PageResults {
get { return this.PageResults; } // re-use generic version
}
Type IPagedList.ElementType {
get { return typeof(Bar); }
}
}
This approach makes the API fully usable via both the generic and non-generic API.
One option is to create 2 interfaces such that:
public interface IPagedListDetails
{
int CurrentPageIndex { get; }
int TotalRecordCount { get; }
int TotalPageCount { get; }
int PageSize { get; }
}
public interface IPagedList<T> : IPagedListDetails
{
IEnumerable<T> PageResults { get; }
}
And then your control:
public class PagedListPager(IPagedListDetails details)
Define two interfaces, first
public interface IPageSpecification
{
int CurrentPageIndex { get; }
int TotalRecordCount { get; }
int TotalPageCount { get; }
int PageSize { get; }
}
public interface IPagedList<T> : IPageSpecification
{
IEnumerable<T> 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