Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d92f186

Browse files
author
Glen Parker
committed
Bugfix: Parameter name matches previous parameter value
When processing scalar tokens, use the correct grouping routine.
1 parent 906a374 commit d92f186

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

‎src/CommandLine/Core/KeyValuePairHelper.cs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
22

3+
using CommandLine.Infrastructure;
4+
using CSharpx;
35
using System.Collections.Generic;
46
using System.Linq;
5-
using CSharpx;
67

78
namespace CommandLine.Core
89
{
@@ -17,7 +18,9 @@ public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> ForSwitch(
1718
public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> ForScalar(
1819
IEnumerable<Token> tokens)
1920
{
20-
return tokens.Pairwise((f, s) => f.Text.ToKeyValuePair(s.Text));
21+
return tokens
22+
.Group(2)
23+
.Select((g) => g[0].Text.ToKeyValuePair(g[1].Text));
2124
}
2225

2326
public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> ForSequence(

‎src/CommandLine/Infrastructure/EnumerableExtensions`1.cs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,36 @@ public static bool Empty<TSource>(this IEnumerable<TSource> source)
3333
{
3434
return !source.Any();
3535
}
36+
37+
/// <summary>
38+
/// Breaks a collection into groups of a specified size.
39+
/// </summary>
40+
/// <param name="source">A collection of <typeparam name="T"/>.
41+
/// <param name="groupSize">The number of items each group shall contain.</param>
42+
/// <returns>An enumeration of <typeparam name="T"/>[].</returns>
43+
/// <remarks>An incomplete group at the end of the source collection will be silently dropped.</remarks>
44+
public static IEnumerable<T[]> Group<T>(this IEnumerable<T> source, int groupSize)
45+
{
46+
if (groupSize < 1)
47+
{
48+
throw new ArgumentOutOfRangeException(nameof(groupSize));
49+
}
50+
51+
T[] group = new T[groupSize];
52+
int groupIndex = 0;
53+
54+
foreach (var item in source)
55+
{
56+
group[groupIndex++] = item;
57+
58+
if (groupIndex == groupSize)
59+
{
60+
yield return group;
61+
62+
group = new T[groupSize];
63+
groupIndex = 0;
64+
}
65+
}
66+
}
3667
}
3768
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /