是否有任何库或项目在Power shell中为PSObjects实现原型继承? 我不这么认为,因为你甚至无法让PSObject将自己标识为自定义类型,例如: PS $obj = new-object psobjectPS $obj.psobject.TypeNames.Insert(0,'M
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这样的通用编程语言的所有功能.