Are there any libraries or projects that implement pro开发者_开发知识库totypal inheritance for PSObjects in Powershell?
I don't think so since you can't even get a PSObject to identify itself as a custom type e.g.:
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.
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.
What about$obj = New-Object -TypeName PSObject -ArgumentList $prototype
?
精彩评论