Powershell 中的原型继承?
是否有任何库或项目可以在 Powershell 中实现 PSObject 的原型继承?
Are there any libraries or projects that implement prototypal inheritance for PSObjects in Powershell?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不这么认为,因为您甚至无法让 PSObject 将自身标识为自定义类型,例如:
但是您可以使用
Add-Type -TypeDefinition
来添加基于 C# 的类定义,并完成继承,在你的脚本中。 PowerShell 的本质仍然是一种命令行 shell 和脚本语言。它不具备(也可能不应该具备)通用编程语言(例如 Python)的所有功能。I don't think so since you can't even get a PSObject to identify itself as a custom type e.g.:
However you can use
Add-Type -TypeDefinition
to sprinkle C#-based class definitions, complete with inheritance, in your script. The thing with PowerShell it is still primarily a command line shell and scripting language. It doesn't have (and probably shouldn't have) all the features of a general purpose programming language like say Python.$obj = New-Object -TypeName PSObject -ArgumentList $prototype
怎么样?What about
$obj = New-Object -TypeName PSObject -ArgumentList $prototype
?