开发者

Prototypal inheritance in Powershell?

开发者 https://www.devze.com 2023-01-15 01:20 出处:网络
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 cu

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消