-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Product, config, environment model updates, paging in selection prompt
- Loading branch information
Showing
20 changed files
with
537 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Linq; | ||
|
||
namespace System.Collections.Generic | ||
{ | ||
public static class ListExtensions | ||
{ | ||
public static List<List<T>> Split<T>(this List<T> source, int chunkSize) | ||
{ | ||
if (source is null || source.Count == 0) | ||
return new List<List<T>>(); | ||
|
||
if (chunkSize > source.Count || chunkSize == 0) | ||
return new List<List<T>> { source }; | ||
|
||
var whole = source.Count / chunkSize; | ||
var remaining = source.Count % chunkSize; | ||
|
||
var from = 0; | ||
var splittedSize = remaining == 0 ? whole : whole + 1; | ||
var splitted = new List<List<T>>(splittedSize); | ||
for (int i = splittedSize; i-- > 0;) | ||
{ | ||
if (remaining != 0 && i == 0) | ||
chunkSize = remaining; | ||
|
||
splitted.Add(new List<T>(source.GetRange(from, chunkSize))); | ||
from += chunkSize; | ||
} | ||
|
||
return splitted; | ||
} | ||
|
||
public static List<List<T>> SplitFilled<T>(this List<T> source, int chunkSize) | ||
{ | ||
if (source is null || source.Count == 0) | ||
return new List<List<T>>(); | ||
|
||
if (chunkSize > source.Count || chunkSize == 0) | ||
return new List<List<T>> { source }; | ||
|
||
var splitted = source.Split(chunkSize); | ||
var last = splitted[splitted.Count - 1]; | ||
if(last.Count < chunkSize) | ||
last.AddRange(Enumerable.Repeat<T>(default, chunkSize - last.Count)); | ||
|
||
return splitted; | ||
} | ||
|
||
public static int PageIndexOf<T>(this List<List<T>> source, T item) | ||
{ | ||
if (source is null || source.Count == 0) | ||
return -1; | ||
|
||
for (int i = 0; i < source.Count; i++) | ||
{ | ||
if (source[i].IndexOf(item) != -1) | ||
return i; | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.