Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6126023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:19:09+00:00 2026-05-23T16:19:09+00:00

Say I have the following interface for exposing a paged list public interface IPagedList<T>

  • 0

Say I have the following interface for exposing a paged list

public interface IPagedList<T>
{
    IEnumerable<T> PageResults { get; }
    int CurrentPageIndex { get; }
    int TotalRecordCount { get; }
    int TotalPageCount { get; }        
    int PageSize { get; }
}   

Now I want to create a paging control

public class PagedListPager<T>
{
    public PagedListPager<T>(IPagedList<T> list)
    {
        _list = list;
    }

    public void RenderPager()
    {
        for (int i = 1; i < list.TotalPageCount; i++)
            RenderLink(i);
    }
}

The paging control has no interest in T (the actual contents of the list). It only requires the number of pages, current page etc. So the only reason PagedListPager is generic is so that it will compile with the generic IPagedList<T> paramater.

Is this a code smell? Should I care that I effectively have a redundant generic?

Is there a standard pattern in a case like this for exposing an additional non-generic version of the interface, so I can remove the generic type on the pager?

public class PagedListPager(IPagedList list)

Edit

I thought I’d also add the current way I’ve solved this problem and invite comments on whether it’s a suitable solution:

public interface IPagedList // non-generic version
{
    IEnumerable<object> PageResults { get; }
    int CurrentPageIndex { get; }
    int TotalRecordCount { get; }
    int TotalPageCount { get; }        
    int PageSize { get; }
}


public class ConcretePagedList<T> : IPagedList<T>, IPagedList
{
    #region IPagedList<T> Members

    public IEnumerable<T> PageResults { get; set; }
    public int CurrentPageIndex { get; set; }
    public int TotalRecordCount { get; set; }
    public int PageSize { get; set; }

    #endregion

    #region IPagedList Members

    IEnumerable<object> IPagedList.PageResults
    {
        get { return PageResults.Cast<object>(); }
    }

    #endregion
}

Now I can pass ConcretePagedList<T> to non-generic classes/functions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:19:10+00:00Added an answer on May 23, 2026 at 4:19 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have the following interface: public interface IMyService { void SimpleMethod(int
Say I have a basic interface like the following: public interface IObjectProvider { IEnumerable<IObject>
Say I have the following Objective-C class: @interface Foo { int someNumber; NSString *someString;
Say I have the following: namespace SomeProject { public interface ISomething { string SomeMethod();
Say I have the following class MyComponent : IMyComponent { public MyComponent(int start_at) {...}
Let's say I have the following Java interface that I may not modify: public
Lets say i have the following set of interfaces.... public interface IStart { void
Ok say I have the following simple classes: public interface IResult<T> { T Results
Say for example, I have the following: public interface IPet { long? Id {
I have the following interfaces defined: public interface IAudit { DateTime DateCreated { get;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.