1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4-
5- namespace Mono . Cecil . Inject
6- {
7- /// <summary>
8- /// Miscellaneous methods for processing enumerable collections.
9- /// </summary>
10- public static class CollectionUtils
11- {
12- /// <summary>
13- /// Runs the specified function for each element.
14- /// </summary>
15- /// <typeparam name="T">Type of the elements in the enumerable.</typeparam>
16- /// <param name="self">Reference to the sequence that contains the elements.</param>
17- /// <param name="action">Action to apply to each element.</param>
18- public static void ForEach < T > ( this IEnumerable < T > self , Action < T > action )
19- {
20- foreach ( T var in self )
21- {
22- action ( var ) ;
23- }
24- }
25-
26- /// <summary>
27- /// Gets a range of elements.
28- /// </summary>
29- /// <param name="self">Refrence to the sequence which to get the values from.</param>
30- /// <param name="start">The index of the first element to pick.</param>
31- /// <param name="end">The end of the last element to pick.</param>
32- /// <typeparam name="T">Type of the sequence.</typeparam>
33- /// <returns>A new instance of <see cref="IEnumerable{T}" /> that containes the selected elements.</returns>
34- public static IEnumerable < T > Range < T > ( this IEnumerable < T > self , int start , int end )
35- {
36- return self . Where ( ( e , i ) => start <= i && i <= end ) ;
37- }
38-
39- /// <summary>
40- /// Gets a range of elements starting from a specified element.
41- /// </summary>
42- /// <typeparam name="T">Type of the sequence.</typeparam>
43- /// <param name="self">Refrence to the sequence which to get the values from.</param>
44- /// <param name="start">The index of the first element to pick.</param>
45- /// <param name="count">The total number of elements to select.</param>
46- /// <returns>A new instance of <see cref="IEnumerable{T}" /> that containes the selected elements.</returns>
47- public static IEnumerable < T > Slice < T > ( this IEnumerable < T > self , int start , int count )
48- {
49- return self . Where ( ( e , i ) => start <= i && i < start + count ) ;
50- }
51- }
1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+
5+ namespace Mono . Cecil . Inject
6+ {
7+ /// <summary>
8+ /// Miscellaneous methods for processing enumerable collections.
9+ /// </summary>
10+ public static class CollectionUtils
11+ {
12+ /// <summary>
13+ /// Runs the specified function for each element.
14+ /// </summary>
15+ /// <typeparam name="T">Type of the elements in the enumerable.</typeparam>
16+ /// <param name="self">Reference to the sequence that contains the elements.</param>
17+ /// <param name="action">Action to apply to each element.</param>
18+ public static void ForEach < T > ( this IEnumerable < T > self , Action < T > action )
19+ {
20+ foreach ( T var in self )
21+ {
22+ action ( var ) ;
23+ }
24+ }
25+
26+ /// <summary>
27+ /// Gets a range of elements.
28+ /// </summary>
29+ /// <param name="self">Refrence to the sequence which to get the values from.</param>
30+ /// <param name="start">The index of the first element to pick.</param>
31+ /// <param name="end">The end of the last element to pick.</param>
32+ /// <typeparam name="T">Type of the sequence.</typeparam>
33+ /// <returns>A new instance of <see cref="IEnumerable{T}" /> that containes the selected elements.</returns>
34+ public static IEnumerable < T > Range < T > ( this IEnumerable < T > self , int start , int end )
35+ {
36+ return self . Where ( ( e , i ) => start <= i && i <= end ) ;
37+ }
38+
39+ /// <summary>
40+ /// Gets a range of elements starting from a specified element.
41+ /// </summary>
42+ /// <typeparam name="T">Type of the sequence.</typeparam>
43+ /// <param name="self">Refrence to the sequence which to get the values from.</param>
44+ /// <param name="start">The index of the first element to pick.</param>
45+ /// <param name="count">The total number of elements to select.</param>
46+ /// <returns>A new instance of <see cref="IEnumerable{T}" /> that containes the selected elements.</returns>
47+ public static IEnumerable < T > Slice < T > ( this IEnumerable < T > self , int start , int count )
48+ {
49+ return self . Where ( ( e , i ) => start <= i && i < start + count ) ;
50+ }
51+ }
5252}
0 commit comments