Skip to content

Commit

Permalink
libs51.0.2 - Make ConnectionToPeer try to connect first at IPv6 then …
Browse files Browse the repository at this point in the history
…at IPv4 if both addresses resolve for remote hostname

CleanUp compiler warnings
CleanUp NUnit warnings
  • Loading branch information
monoman committed Jan 23, 2024
1 parent d86213a commit f30f782
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions InterlockLedger.Commons/Extensions/System/PageOfExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static PageOf<T> Paginate<T>(this IEnumerable<T>? resultList, ushort page
var list = resultList.Safe();
if (pageSize == 0)
return new PageOf<T>(list.ToArray(), lastToFirst);
ushort totalPages = (ushort)Math.Min((list.Count() + pageSize - 1) / pageSize, ushort.MaxValue);
ushort totalPages = CalculateTotalPages(list, pageSize);
if (page >= totalPages)
page = (ushort)(totalPages > 0 ? totalPages - 1 : 0);
return new PageOf<T>(list.Skip(page * pageSize).Take(pageSize).ToArray(), page, pageSize, totalPages, lastToFirst);
Expand All @@ -79,11 +79,16 @@ public static PageOf<T> Paginate<T, TT>(this IEnumerable<TT>? resultList, ushort
var list = resultList.Safe().SkipDefaults();
if (pageSize == 0)
return new PageOf<T>(list.Select(converter).ToArray(), lastToFirst);
ushort totalPages = (ushort)Math.Min((list.Count() + pageSize - 1) / pageSize, ushort.MaxValue);
ushort totalPages = CalculateTotalPages(list, pageSize);
if (page >= totalPages)
page = (ushort)(totalPages > 0 ? totalPages - 1 : 0);
return new PageOf<T>(list.Skip(page * pageSize).Take(pageSize).Select(converter).ToArray(), page, pageSize, totalPages, lastToFirst);
}
private static ushort CalculateTotalPages<T>(IEnumerable<T> list, byte pageSize) {
int count = (list is ICollection<T> collection) ? collection.Count : list.Count();
return (ushort)Math.Min((count + pageSize - 1) / pageSize, ushort.MaxValue);
}


public static PageOf<T> Safe<T>(this PageOf<T>? page) =>
page ?? PageOf<T>.Empty;
Expand Down

0 comments on commit f30f782

Please sign in to comment.