与这个有趣的问题相关zett42 https://stackoverflow.com/q/71631192/15339544,看起来像对象实例隐藏或私人的特性可能会打破用于显示格式 https://stackoverflow.com/questions/71631192/implicit-conversion-to-bool-of-struct-defined-in-c-sharp-fails-in-powershell/71632418?noredirect=1#comment126599208_71632418当通过管道输送到Get-Member
也Select-Object *
.
希望有人能够对这种奇怪的行为有所启发。
class MyBool2 {
hidden [bool] $Value
MyBool2([bool] $Value) {
$this.Value = $Value
}
[string] ToString() {
return "$($this.Value)"
}
}
$instance = [MyBool2] $true
实例初始化后,从我们的控制台:
PS /> $instance
True
PS /> $instance | Get-Member
TypeName: MyBool2
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
PS /> $instance
PS /> $instance.ToString()
True
NOTE,此行为仅在 PowerShell Core 中观察到。Windows PowerShell 似乎并非如此.
GitHub 问题 #17071 https://github.com/PowerShell/PowerShell/issues/17071已提交给任何想要加入的人。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)