powershell - PowerShell 中的成员类型(ScriptProperty、Property 和 NoteProperty)

标签 powershell powershell-3.0

PowerShell 中有哪些成员类型,例如 ScriptProperty、Property、Method、NoteProperty、Alias 和 EventProperty?

例如,CPU是脚本属性。我们如何将其归类为 ScriptProperty?

我想了解所有这些的简要信息。

最佳答案

曾经在 MSDN 上对 PowerShell 扩展类型系统有过很好的介绍(不幸的是,自 PSH v1 以来的更改丢失了)。

本质上,PowerShell 允许通过 PSObject 使用其他成员包装底层 .NET 对象。类型。这可以通过多种方式完成:

  • 使用 Add-Member (给予最大控制)
  • 通过将散列而不是名称传递给 Select-Object 来指定其他属性的属性参数
  • 使用 New-Object创建一个 PSObject和路过
  • 在 .NET 代码(C#、VB 等)中使用底层 PSObject属性和 PSMemberInfo 子类型。

  • 不同类型的“扩展”成员由 PSMemberInfo 表示。子类型,包括:
  • NoteProperty:.NET 对象或值。
  • AliasProperty:另一个属性的别名(例如,一个集合可以同时具有 Count 和 Length 属性,其中一个是另一个的另一个名称)。
  • ScriptProperty:一个用 PowerShell 编写的具有 get 和 set 方法的属性。
  • CodeProperty:带有 get 和 set 方法的属性,用 C#、VB 等编写。

  • 等等。

    关于powershell - PowerShell 中的成员类型(ScriptProperty、Property 和 NoteProperty),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19975920/

    相关文章:

    debugging - 有没有办法在错误时进入调试器?

    powershell - 获取VS2015中的Nuget软件包的许可证

    PowerShell 测试连接 "On first response"

    .net - Powershell正则表达式用于随机除以回车符的字符串

    powershell - 使用PowerShell执行火灾并忘记Web请求

    Powershell - Azure Data Lake Store 中的递归

    asp.net - 如何在powershell中执行具有[[FromForm]]参数的API PUT方法

    powershell - 是否可以从 CloudFormation 检索作为参数传入的值以用于其他用途?

    powershell - 通过Combobox Powershell获取更多选择信息

    powershell - 交替串