-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed no more needed name mangling
- Loading branch information
Showing
1 changed file
with
67 additions
and
67 deletions.
There are no files selected for viewing
134 changes: 67 additions & 67 deletions
134
.../Infrastructure/EnumerableExtensions`1.cs → ...ne/Infrastructure/EnumerableExtensions.cs
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 |
---|---|---|
@@ -1,68 +1,68 @@ | ||
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace CommandLine.Infrastructure | ||
{ | ||
static class EnumerableExtensions | ||
{ | ||
public static int IndexOf<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) | ||
{ | ||
var index = -1; | ||
foreach (var item in source) | ||
{ | ||
index++; | ||
if (predicate(item)) | ||
{ | ||
break; | ||
} | ||
} | ||
return index; | ||
} | ||
|
||
public static object ToUntypedArray(this IEnumerable<object> value, Type type) | ||
{ | ||
var array = Array.CreateInstance(type, value.Count()); | ||
value.ToArray().CopyTo(array, 0); | ||
return array; | ||
} | ||
|
||
public static bool Empty<TSource>(this IEnumerable<TSource> source) | ||
{ | ||
return !source.Any(); | ||
} | ||
|
||
/// <summary> | ||
/// Breaks a collection into groups of a specified size. | ||
/// </summary> | ||
/// <param name="source">A collection of <typeparam name="T"/>.</param> | ||
/// <param name="groupSize">The number of items each group shall contain.</param> | ||
/// <returns>An enumeration of T[].</returns> | ||
/// <remarks>An incomplete group at the end of the source collection will be silently dropped.</remarks> | ||
public static IEnumerable<T[]> Group<T>(this IEnumerable<T> source, int groupSize) | ||
{ | ||
if (groupSize < 1) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(groupSize)); | ||
} | ||
|
||
T[] group = new T[groupSize]; | ||
int groupIndex = 0; | ||
|
||
foreach (var item in source) | ||
{ | ||
group[groupIndex++] = item; | ||
|
||
if (groupIndex == groupSize) | ||
{ | ||
yield return group; | ||
|
||
group = new T[groupSize]; | ||
groupIndex = 0; | ||
} | ||
} | ||
} | ||
} | ||
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace CommandLine.Infrastructure | ||
{ | ||
static class EnumerableExtensions | ||
{ | ||
public static int IndexOf<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) | ||
{ | ||
var index = -1; | ||
foreach (var item in source) | ||
{ | ||
index++; | ||
if (predicate(item)) | ||
{ | ||
break; | ||
} | ||
} | ||
return index; | ||
} | ||
|
||
public static object ToUntypedArray(this IEnumerable<object> value, Type type) | ||
{ | ||
var array = Array.CreateInstance(type, value.Count()); | ||
value.ToArray().CopyTo(array, 0); | ||
return array; | ||
} | ||
|
||
public static bool Empty<TSource>(this IEnumerable<TSource> source) | ||
{ | ||
return !source.Any(); | ||
} | ||
|
||
/// <summary> | ||
/// Breaks a collection into groups of a specified size. | ||
/// </summary> | ||
/// <param name="source">A collection of <typeparam name="T"/>.</param> | ||
/// <param name="groupSize">The number of items each group shall contain.</param> | ||
/// <returns>An enumeration of T[].</returns> | ||
/// <remarks>An incomplete group at the end of the source collection will be silently dropped.</remarks> | ||
public static IEnumerable<T[]> Group<T>(this IEnumerable<T> source, int groupSize) | ||
{ | ||
if (groupSize < 1) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(groupSize)); | ||
} | ||
|
||
T[] group = new T[groupSize]; | ||
int groupIndex = 0; | ||
|
||
foreach (var item in source) | ||
{ | ||
group[groupIndex++] = item; | ||
|
||
if (groupIndex == groupSize) | ||
{ | ||
yield return group; | ||
|
||
group = new T[groupSize]; | ||
groupIndex = 0; | ||
} | ||
} | ||
} | ||
} | ||
} |