1+ <#
2+ . SYNOPSIS
3+ Resolves an Attribute to a CommandInfo
4+ . DESCRIPTION
5+ Resolves an Attribute to one or more CommandInfo.
6+ . EXAMPLE
7+ {
8+ [InvokePipeScript()]$null
9+ }.Ast.EndBlock.Statements[0].PipelineElements[0].Expression.Attribute.ResolvedCommand
10+ . EXAMPLE
11+ {
12+ [Microsoft.PowerShell.Core.GetCommand()]$null
13+ }.Ast.EndBlock.Statements[0].PipelineElements[0].Expression.Attribute.ResolvedCommand
14+ . EXAMPLE
15+ {
16+ [Get_Command()]$null
17+ }.Ast.EndBlock.Statements[0].PipelineElements[0].Expression.Attribute.ResolvedCommand
18+ . EXAMPLE
19+ {
20+ [GetCommand()]$null
21+ }.Ast.EndBlock.Statements[0].PipelineElements[0].Expression.Attribute.ResolvedCommand
22+ . EXAMPLE
23+ {
24+ [cmd()]$null
25+ }.EndBlock.Statements[0].PipelineElements[0].Expression.Attribute.ResolvedCommand
26+ #>
27+ # Get the name of the transpiler.
28+ $transpilerStepName =
29+ if ($this.TypeName.IsGeneric ) {
30+ $this.TypeName.TypeName.Name
31+ } else {
32+ $this.TypeName.Name
33+ }
34+ $decamelCase = [Regex ]::new(' (?<=[a-z])(?=[A-Z])' )
35+ @ (
36+ # If a Transpiler exists by that name, it will be returned first.
37+ Get-Transpiler - TranspilerName $transpilerStepName
38+ # Then, any periods in the attribute name will be converted to slashes,
39+ $fullCommandName = $transpilerStepName -replace ' \.' , ' \' -replace
40+ ' _' , ' -' # and any underscores to dashes.
41+
42+ # Then, the first CamelCased code will have a - injected in between the CamelCase.
43+ $fullCommandName = $decamelCase.Replace ($fullCommandName , ' -' , 1 )
44+ # Now we will try to find the command.
45+ $ExecutionContext.SessionState.InvokeCommand.GetCommand ($fullCommandName , ' All' )
46+ )
0 commit comments