BadScript 2
Loading...
Searching...
No Matches
CommandLine.Infrastructure.EnumerableExtensions Class Reference

Static Public Member Functions

static int IndexOf< TSource > (this IEnumerable< TSource > source, Func< TSource, bool > predicate)
 
static object ToUntypedArray (this IEnumerable< object > value, Type type)
 
static bool Empty< TSource > (this IEnumerable< TSource > source)
 
static IEnumerable< T[]> Group< T > (this IEnumerable< T > source, int groupSize)
 Breaks a collection into groups of a specified size.
 

Detailed Description

Definition at line 9 of file EnumerableExtensions.cs.

Member Function Documentation

◆ Empty< TSource >()

static bool CommandLine.Infrastructure.EnumerableExtensions.Empty< TSource > ( this IEnumerable< TSource >  source)
static

Definition at line 38 of file EnumerableExtensions.cs.

39 {
40 return !source.Any();
41 }

◆ Group< T >()

static IEnumerable< T[]> CommandLine.Infrastructure.EnumerableExtensions.Group< T > ( this IEnumerable< T >  source,
int  groupSize 
)
static

Breaks a collection into groups of a specified size.

Parameters
sourceA collection of
Template Parameters
T
Parameters
groupSizeThe number of items each group shall contain.
Returns
An enumeration of T[].

An incomplete group at the end of the source collection will be silently dropped.

Definition at line 54 of file EnumerableExtensions.cs.

55 {
56 if (groupSize < 1)
57 {
58 throw new ArgumentOutOfRangeException(nameof(groupSize));
59 }
60
61 T[] group = new T[groupSize];
62 int groupIndex = 0;
63
64 foreach (T item in source)
65 {
66 group[groupIndex++] = item;
67
68 if (groupIndex == groupSize)
69 {
70 yield return group;
71
72 group = new T[groupSize];
73 groupIndex = 0;
74 }
75 }
76 }

◆ IndexOf< TSource >()

static int CommandLine.Infrastructure.EnumerableExtensions.IndexOf< TSource > ( this IEnumerable< TSource >  source,
Func< TSource, bool >  predicate 
)
static

Definition at line 11 of file EnumerableExtensions.cs.

12 {
13 int index = -1;
14
15 foreach (TSource item in source)
16 {
17 index++;
18
19 if (predicate(item))
20 {
21 break;
22 }
23 }
24
25 return index;
26 }

◆ ToUntypedArray()

static object CommandLine.Infrastructure.EnumerableExtensions.ToUntypedArray ( this IEnumerable< object >  value,
Type  type 
)
static

Definition at line 28 of file EnumerableExtensions.cs.

29 {
30 Array array = Array.CreateInstance(type, value.Count());
31
32 value.ToArray()
33 .CopyTo(array, 0);
34
35 return array;
36 }

The documentation for this class was generated from the following file: