Prototypal inheritance in Powershell?

Are there libraries or projects implementing prototype inheritance for PSObjects in Powershell?

+4
source share
2 answers

I don’t think so, since you cannot even force PSObject to identify itself as a custom type, for example:

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 class definitions based on C #, complete with inheritance, in a script. PowerShell still has a command line shell and scripting language. It does not have (and probably shouldn't) all the functions of a general-purpose programming language, such as Python.

+4
source

What about $obj = New-Object -TypeName PSObject -ArgumentList $prototype ?

0
source

All Articles