Ant*_*lov 5 reflection powershell
我需要$this
在静态类中工作!怎么实现呢?任何解决方法?我已经分析Get-PSCallStack
了类上下文的返回,发现没什么用处.
我需要这个用于(a)日志记录和(b)调用同一类的其他静态方法,而不是一次又一次地提及它的名字.
示例代码(PowerShell v5):
class foo {
static [void]DoSomething() {
[foo]::DoAnything() #works
#$this.DoAnything #not working
$static_this = [foo]
$static_this::DoAnything() #works
}
static [void]DoAnything() {
echo "Done"
}
}
[foo]::DoSomething()
Run Code Online (Sandbox Code Playgroud)