PowerShell 中的 Class、Interface、Mixin 等概念是什么?它支持 OOP 吗?如果是这样,我在哪里可以阅读有关此内容的信息?
最佳答案
您可以使用 Add-Type
在 PowerShell v2.0 中定义新类型。小命令:
DETAILED DESCRIPTION
The Add-Type cmdlet lets you define a .NET class in your Windows PowerShell session. You can then instantiate objects (by using the New-Object cmdlet) and use the objects, just as you would use any .NET ob ject. If you add an Add-Type command to your Windows PowerShell profile, the class will be available in all Windows PowerShell sessions.
You can specify the type by specifying an existing assembly or source code files, or you can specify source code in line or saved in a variable. You can even specify only a method and Add-Type will define and generate the class. You can use this feature to make Platform Invoke (P/Invoke) calls to unmanaged functions in Windows PowerShell. If you specify source code, Add-Type compiles the specified source co de and generates an in-memory assembly that contains the new .NET types.
You can use the parameters of Add-Type to specify an alternate language and compiler (CSharp is the default), compiler options, assembly dependencies, the class namespace, and the names of the type and the resulting assembly.
help Add-Type
想要查询更多的信息。另请参阅:
关于oop - PowerShell 是否支持 OOP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/683811/