Generic Implementation for Paging Class in c# I have created one generic Page class for store paging information with its data.

The class look like:

public class Page&lt;T&gt;
     where T : new()
{

    private List&lt;T&gt; _list = new List&lt;T&gt;();

    [JsonProperty(PropertyName = "total_count")]
    public long TotalCount { get; set; }

    [JsonProperty(PropertyName = "page_start")]
    public long PageStart { get; set; }

    [JsonProperty(PropertyName = "page_size")]
    public long PageSize { get; set; }

    [JsonProperty(PropertyName = "list")]
    public List&lt;T&gt; List
    {
        get { return _list; }
        set { _list = value; }
    }
}


For every table model of my application uses generic Page class in repository for return PageSize and its total records with its List.

My repository use like below:

public class StudentRepository
{
    private readonly CountingCloud_DevContext _dbContext;
    public StudentRepository(CountingCloud_DevContext dbContext)
    {
        _dbContext = dbContext;
    }
    public Page&lt;StudentResponse&gt; Get(Dictionary&lt;string, object&gt; filterParameters)
    {
        var resultfinal = new Page&lt;StudentResponse&gt;();
        int from = 0, size = 10;
        resultfinal = Paging(resultfinal, filterParameters, ref from, ref size);

        var query = _dbContext.Students.ToList();
        var result = query.Select(x =&gt; new StudentResponse
        {
            Id = x.Id,
            Name = x.Name
        });
        resultfinal.TotalCount = result.Count();
        query = result.Skip(from).Take(size);
        return resultfinal;
    }

    private static Page&lt;StudentResponse&gt; Paging(Page&lt;StudentResponse&gt; pagingResponse, Dictionary&lt;string, object&gt; parameters, ref int from, ref int size)
    {
        if (parameters != null)
        {
            if (parameters.ContainsKey("PageSize") &amp;&amp; parameters.ContainsKey("PageStart"))
            {
                if (Convert.ToInt32(parameters["PageSize"]) != 0)
                {
                    size = Convert.ToInt32(parameters["PageSize"]);
                    from = (Convert.ToInt32(parameters["PageStart"]) - 1) * size;
                    pagingResponse.PageSize = size;
                    pagingResponse.PageStart = Convert.ToInt32(parameters["PageStart"]);
                }
            }
            else
            {
                pagingResponse.PageSize = size;
                pagingResponse.PageStart = from + 1;
            }
        }
        else
        {
            pagingResponse.PageSize = size;
            pagingResponse.PageStart = from + 1;
        }
        return pagingResponse;
    }
}


Currently Paging() method I have use for all table like my other Repository is for Employee then for that paging method is look like below:

private static Page&lt;EmployeeResponse&gt; Paging(Page&lt;StudentResponse&gt; pagingResponse, Dictionary&lt;string, object&gt; parameters, ref int from, ref int size)
{
    if (parameters != null)
    {
        if (parameters.ContainsKey("PageSize") &amp;&amp; parameters.ContainsKey("PageStart"))
        {
            if (Convert.ToInt32(parameters["PageSize"]) != 0)
            {
                size = Convert.ToInt32(parameters["PageSize"]);
                from = (Convert.ToInt32(parameters["PageStart"]) - 1) * size;
                pagingResponse.PageSize = size;
                pagingResponse.PageStart = Convert.ToInt32(parameters["PageStart"]);
            }
        }
        else
        {
            pagingResponse.PageSize = size;
            pagingResponse.PageStart = from + 1;
        }
    }
    else
    {
      pagingResponse.PageSize = size;
        pagingResponse.PageStart = from + 1;
    }
    return pagingResponse;
}


I would like make this private method is generic so all repository use same,
please suggest me what I am implemented is correct or any better improvement for code any changes.
Some quick remarks:


Names shouldn't contain underscores etc: CountingCloud_DevContext. (The exception is the underscore at the start of a private member (e.g. _dbContext.)
If you have a Dictionary, do not use ContainsKey if you need to retrieve the value associated with that key. This is why the much more efficient TryGetValue exists.
Do not copy-paste magic strings (e.g. "PageSize") all over the place. Store them as const in a relevant class and use that.
But most importantly: what's the point of Dictionary&lt;string, object&gt; when all it contains is two specific key-value pairs? Why not make a PagingParameters class with PageSize and PageStart as nullable ints? Don't make things too generic, because all you end up is making things harder for yourself.
Also avoid making a generic Repository class. It likely will create more work and solve nothing.