forked from commandlineparser/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeLookup.cs
More file actions
34 lines (31 loc) · 1.31 KB
/
TypeLookup.cs
File metadata and controls
34 lines (31 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 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;
using CSharpx;
namespace CommandLine.Core
{
static class TypeLookup
{
public static Maybe<TypeDescriptor> FindTypeDescriptorAndSibling(
string name,
IEnumerable<OptionSpecification> specifications,
StringComparer comparer)
{
var info =
specifications.SingleOrDefault(a => name.MatchName(a.ShortName, a.LongName, comparer))
.ToMaybe()
.Map(
first =>
{
var descr = TypeDescriptor.Create(first.TargetType, first.Max);
var next = specifications
.SkipWhile(s => s.Equals(first)).Take(1)
.SingleOrDefault(x => x.IsValue()).ToMaybe()
.Map(second => TypeDescriptor.Create(second.TargetType, second.Max));
return descr.WithNextValue(next);
});
return info;
}
}
}