Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/System.Management.Automation/engine/InvocationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ public string Line
}
}

/// <summary>
/// The full text of the invocation statement, may span multiple lines.
/// </summary>
/// <value>Statement that was entered to invoke this command.</value>
public string Statement
{
get
{
return ScriptPosition.Text;
}
}

/// <summary>
/// Formatted message indicating where the cmdlet appeared
/// in the line.
Expand Down
19 changes: 19 additions & 0 deletions test/powershell/Language/Scripting/MyInvocation.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ Describe 'Testing of MyInvocation' -Tags "CI" {
{ & myfilter } | Should -Not -Throw
}

Context 'MyInvocation works with multi-line invocations' {
It 'MyInvocation.Statement works in & Script block' {
$a = & {
$MyInvocation.Statement
}
$a.IndexOf('& {
$MyInvocation.Statement
}') |Should -BeGreaterThan -1
}
It 'MyInvocation.Statement works in dot sourced Script block' {
$a = . {
$MyInvocation.Statement
}
$a.IndexOf('. {
$MyInvocation.Statement
}') |Should -BeGreaterThan -1
}
}

Context 'MyInvocation works in Script block' {

It 'MyInvocation works in dot sourced Script block' {
Expand Down