BadScript 2
Loading...
Searching...
No Matches
TypeLookup.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4using System.Collections.Generic;
5using System.Linq;
6
7using CSharpx;
8
9namespace CommandLine.Core
10{
11 internal static class TypeLookup
12 {
14 IEnumerable<OptionSpecification>
15 specifications,
16 StringComparer comparer)
17 {
19 specifications.SingleOrDefault(a => name.MatchName(a.ShortName, a.LongName, comparer))
20 .ToMaybe()
21 .Map(first =>
22 {
23 TypeDescriptor descr = TypeDescriptor.Create(first.TargetType, first.Max);
24
25 Maybe<TypeDescriptor> next = specifications
26 .SkipWhile(s => s.Equals(first))
27 .Take(1)
28 .SingleOrDefault(x => x.IsValue())
29 .ToMaybe()
30 .Map(second =>
31 TypeDescriptor.Create(second.TargetType,
32 second.Max
33 )
34 );
35
36 return descr.WithNextValue(next);
37 }
38 );
39
40 return info;
41 }
42 }
43}
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
static Maybe< TypeDescriptor > FindTypeDescriptorAndSibling(string name, IEnumerable< OptionSpecification > specifications, StringComparer comparer)
Definition TypeLookup.cs:13
static TypeDescriptor Create(TargetType tag, Maybe< int > maximumItems, TypeDescriptor next=default)