4

是否有任何库或项目为 Powershell 中的 PSObjects 实现原型继承?

4

2 回答 2

4

我不这么认为,因为您甚至无法让 PSObject 将自己标识为自定义类型,例如:

PS> $obj = new-object psobject
PS> $obj.psobject.TypeNames.Insert(0,'MyCustomType')
PS> $obj.psobject.TypeNames
MyCustomType
System.Management.Automation.PSCustomObject
System.Object
PS> $obj -is [MyCustomType]
Unable to find type [MyCustomType]: make sure that the assembly 
containing this type is loaded.

但是,您可以Add-Type -TypeDefinition在脚本中使用基于 C# 的类定义以及继承。PowerShell 的东西仍然主要是命令行 shell 和脚本语言。它没有(也可能不应该有)通用编程语言的所有特性,比如 Python。

于 2010-09-08T13:40:33.030 回答
0

怎么样$obj = New-Object -TypeName PSObject -ArgumentList $prototype

于 2012-06-07T20:43:13.507 回答