-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathNameExtensions.cs
More file actions
35 lines (31 loc) · 1.18 KB
/
NameExtensions.cs
File metadata and controls
35 lines (31 loc) · 1.18 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
35
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using System.Linq;
namespace CommandLine.Core
{
static class NameExtensions
{
public static bool MatchName(this string value, string shortName, string[] longNames, StringComparer comparer)
{
return value.Length == 1
? comparer.Equals(value, shortName)
: longNames.Any(longName => comparer.Equals(value, longName));
}
public static NameInfo FromOptionSpecification(this OptionSpecification specification)
{
return new NameInfo(
specification.ShortName,
specification.LongNames);
}
public static NameInfo FromSpecification(this Specification specification)
{
switch (specification.Tag)
{
case SpecificationType.Option:
return FromOptionSpecification((OptionSpecification)specification);
default:
return NameInfo.EmptyName;
}
}
}
}