forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetVerbCommand.cs
More file actions
81 lines (73 loc) · 2.72 KB
/
Copy pathGetVerbCommand.cs
File metadata and controls
81 lines (73 loc) · 2.72 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Management.Automation;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// Implementation of the Get Verb Command
/// </summary>
[Cmdlet(VerbsCommon.Get, "Verb", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=160712")]
[OutputType(typeof(VerbInfo))]
public class GetVerbCommand : Cmdlet
{
/// <summary>
/// Optional Verb filter
/// </summary>
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0)]
public string[] Verb
{
get; set;
}
/// <summary>
/// Optional Group filter
/// </summary>
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 1)]
[ValidateSet("Common", "Communications", "Data", "Diagnostic", "Lifecycle", "Other", "Security")]
public string[] Group
{
get; set;
}
/// <summary>
/// Returns a list of verbs
/// </summary>
protected override void ProcessRecord()
{
Type[] verbTypes = new Type[] { typeof(VerbsCommon), typeof(VerbsCommunications), typeof(VerbsData),
typeof(VerbsDiagnostic), typeof(VerbsLifecycle), typeof(VerbsOther), typeof(VerbsSecurity) };
Collection<WildcardPattern> matchingVerbs = SessionStateUtilities.CreateWildcardsFromStrings(
this.Verb,
WildcardOptions.IgnoreCase
);
foreach (Type type in verbTypes)
{
string groupName = type.Name.Substring(5);
if (this.Group != null)
{
if (!SessionStateUtilities.CollectionContainsValue(this.Group, groupName, StringComparer.OrdinalIgnoreCase))
{
continue;
}
}
foreach (FieldInfo field in type.GetFields())
{
if (field.IsLiteral)
{
if (this.Verb != null)
{
if (!SessionStateUtilities.MatchesAnyWildcardPattern(field.Name, matchingVerbs, false))
{
continue;
}
}
VerbInfo verb = new VerbInfo();
verb.Verb = field.Name;
verb.Group = groupName;
WriteObject(verb);
}
}
}
}
}
}