oop - PowerShell 是否支持 OOP?

标签 oop powershell

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想要查询更多的信息。

另请参阅:
  • How do I create a custom type in PowerShell for my scripts to use?
  • http://thepowershellguy.com/blogs/posh/archive/2008/06/02/powershell-v2-ctp2-making-custom-enums-using-add-type.aspx
  • 关于oop - PowerShell 是否支持 OOP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/683811/

    相关文章:

    作为提升用户的 Python 子进程脚本

    powershell - 如何使用 Powershell 访问其他用户的注册表配置单元?

    powershell - 通过 WMI 远程确定 PowerShell 版本

    PHP 'instanceof' 类常量失败

    oop - 面向对象设计中的方法

    events - 什么时候使用事件?

    java - "Tell Don' t 请问,"shouldn' t所有方法都无效吗?

    powershell - 用 'X'的值初始化 'X'大小为 '0'的矩阵

    windows - 我正在从后台服务运行 powershell 脚本,为什么有些命令不能像这样工作?

    java - 无法在java中导入类。代码拒绝相信它存在