Skip to content

Commit 1dc1909

Browse files
committed
Use ReadOnlyList instead of List
1 parent 62f1a63 commit 1dc1909

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/LinkDotNet.Blog.Infrastructure/PagedList.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class PagedList<T> : IPagedList<T>
99
{
1010
public static readonly PagedList<T> Empty = new(Enumerable.Empty<T>(), 0, 0, 0);
1111

12-
private readonly IList<T> subset;
12+
private readonly IReadOnlyList<T> subset;
1313
private readonly int totalPages;
1414

1515
public PagedList(IEnumerable<T> items, int pageNumber, int pageSize)
@@ -21,7 +21,7 @@ public PagedList(IEnumerable<T> items, int count, int pageNumber, int pageSize)
2121
{
2222
PageNumber = pageNumber;
2323
totalPages = (int)Math.Ceiling(count / (double)pageSize);
24-
subset = items as IList<T> ?? new List<T>(items);
24+
subset = items as IReadOnlyList<T> ?? items.ToArray();
2525
}
2626

2727
public int PageNumber { get; }

src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/PaginatedListQueryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static Task<IPagedList<T>> ToPagedList<T>(this IEnumerable<T> source, int
1414
var items = source
1515
.Skip((pageIndex - 1) * pageSize)
1616
.Take(pageSize)
17-
.ToList();
17+
.ToArray();
1818
return Task.FromResult<IPagedList<T>>(new PagedList<T>(items, count, pageIndex, pageSize));
1919
}
2020

src/LinkDotNet.Blog.Infrastructure/Persistence/RavenDb/PaginatedListQueryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IRavenQueryable
1515
var items = await source
1616
.Skip((pageIndex - 1) * pageSize)
1717
.Take(pageSize)
18-
.ToListAsync(token);
18+
.ToArrayAsync(token);
1919
return new PagedList<T>(items, count, pageIndex, pageSize);
2020
}
2121

src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/PaginatedListQueryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IQueryable<T> s
1818
var items = source
1919
.Skip((page - 1) * pageSize)
2020
.Take(pageSize)
21-
.ToList();
21+
.ToArray();
2222
return new PagedList<T>(items, count, page, pageSize);
2323
}
2424

0 commit comments

Comments
 (0)