作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要$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()
最佳答案
静态类没有 this
指针。见 MSDN
Static member functions, because they exist at the class level and not as part of an object, do not have a this pointer. It is an error to refer to this in a static method.
关于powershell - 如何在PowerShell静态类方法中获取当前类名/对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39055860/
我是一名优秀的程序员,十分优秀!