mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add Statement property to $MyInvocation (#19027)
This commit is contained in:
@@ -271,6 +271,18 @@ namespace System.Management.Automation
|
||||
}
|
||||
}
|
||||
|
||||
/// <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.
|
||||
|
||||
@@ -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' {
|
||||
|
||||
Reference in New Issue
Block a user