forked from commandlineparser/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerb.cs
More file actions
55 lines (45 loc) · 1.78 KB
/
Verb.cs
File metadata and controls
55 lines (45 loc) · 1.78 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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 System.Reflection;
namespace CommandLine.Core
{
sealed class Verb
{
public Verb(string name, string helpText, bool hidden, bool isDefault, string[] aliases)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
Name = name;
HelpText = helpText ?? throw new ArgumentNullException(nameof(helpText));
Hidden = hidden;
IsDefault = isDefault;
Aliases = aliases ?? new string[0];
}
public string Name { get; private set; }
public string HelpText { get; private set; }
public bool Hidden { get; private set; }
public bool IsDefault { get; private set; }
public string[] Aliases { get; private set; }
public static Verb FromAttribute(VerbAttribute attribute)
{
return new Verb(
attribute.Name,
attribute.HelpText,
attribute.Hidden,
attribute.IsDefault,
attribute.Aliases
);
}
public static IEnumerable<Tuple<Verb, Type>> SelectFromTypes(IEnumerable<Type> types)
{
return from type in types
let attrs = type.GetTypeInfo().GetCustomAttributes(typeof(VerbAttribute), true).ToArray()
where attrs.Length == 1
select Tuple.Create(
FromAttribute((VerbAttribute)attrs.Single()),
type);
}
}
}