Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an empty paged list #44

Open
wis3guy opened this issue Sep 26, 2014 · 6 comments
Open

Create an empty paged list #44

wis3guy opened this issue Sep 26, 2014 · 6 comments

Comments

@wis3guy
Copy link

wis3guy commented Sep 26, 2014

Sometimes it is useful to be able to create an empty instance of PagedList. As i did not want to change the library, i worked around this by doing this:

public static class PagedList
{
    /// <summary>
    /// Factory method for an empty <see cref="PagedList{T}"/>
    /// </summary>
    /// <typeparam name="T">Type of data contained in the list</typeparam>
    /// <returns>An empty paged list</returns>
    public static IPagedList<T> Empty<T>()
    {
        return new List<T>().ToPagedList(0, 1);
    }
}

and then using

var empty = PagedList.Empty<SomeType>();

it would be cleaner if i could simply do:

var empty = new PagedList<SomeType>();
@martijnboland
Copy link
Owner

Sure, it's possible. Just curious: in what situations do you need an empty list?

@wis3guy
Copy link
Author

wis3guy commented Sep 29, 2014

F.ex when i want to return an empty search result. Sometimes i can already determine that a search is not going to yield any results without firing a query.

Or, f.ex. as a default values on my models. I always want my objects to be in a valid state, which means that in the default constructor i want to set my collection properties to an empty collection.

@martijnboland
Copy link
Owner

Alright, clear

@martijnboland
Copy link
Owner

Just looking at it, but I think it doesn't make any sense to create an empty constructor, because we'll have to assume some pagesize. Probably better to just use one of the existing constructors:

var emptyList = new PagedList<SomeType>(null, 0, 1);

@wis3guy
Copy link
Author

wis3guy commented Oct 6, 2014

The idea is not to create a mutable pagedlist, rather an immutable one
which indicates no results.

On Sunday, October 5, 2014, Martijn Boland [email protected] wrote:

Just looking at it, but I think it doesn't make any sense to create an
empty constructor, because we'll have to assume some pagesize. Probably
better to just use one of the existing constructors:

var emptyList = new PagedList(null, 0, 1);


Reply to this email directly or view it on GitHub
#44 (comment)
.

Ciao,
Geoffrey

Geoffrey Braaf | +31655793290
Freelance .NET Software Architect & Passionate Developer |
http://wis3guy.net
Findsi: find-as-i | http://www.findsi.com

@meatgithub
Copy link

Thanks for this tip wis3guy. It was indeed helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants