在PowerShell中使用枚举类型
来源:互联网 发布:国轩高科待遇 知乎 编辑:程序博客网 时间:2024/05/22 15:47
我们都知道PowerShell是基于NET Framework库的,自从PowerShell开始支持Class关键字后,我们也可以在PowerShell使用Enum枚举,我们先给出下面这个完整的小例子。
#requires -Version 5 enum MyFruit { Apple Orange Watermelon} function Select-Fruit{ param ( [MyFruit] [Parameter(Mandatory=$true)] $Fruit ) "You like $Fruit"}Select-Fruit
PS C:\Users\Administrator> C:\Sample\Untitled4.ps1cmdlet Select-Fruit at command pipeline position 1Supply values for the following parameters:Fruit: AppleYou like Apple
enum MyFruit { Apple Orange Watermelon}
[MyFruit] [Parameter(Mandatory=$true)] $Fruit
我们可以简单修改下脚本,看看是否它是一个枚举:
#requires -Version 5 enum MyFruit { Apple Orange Watermelon} function Select-Fruit{ param ( [MyFruit] [Parameter(Mandatory=$true)] $Fruit ) $Type = ($Fruit).GetType() | Select-Object -ExpandProperty BaseType "The type is $Type"}Select-Fruit
得到结果如下,就是这样!
PS C:\Users\Administrator> C:\XMLSample\Untitled4.ps1cmdlet Select-Fruit at command pipeline position 1Supply values for the following parameters:Fruit: appleThe type is System.Enum
0 0
- 在PowerShell中使用枚举类型
- 枚举类型在Java中使用
- 在PowerShell中使用Vim
- WCF 中使用枚举类型
- ComboBoxPropertyDescriptor 中使用枚举类型
- WebService中使用枚举类型
- 在 PowerShell 中使用 WMI 远程调用
- 使用Splatting在PowerShell中传递参数
- 如何在PowerShell中使用.NET Framework
- 在 PowerShell 中使用 SQL Server
- 在PowerShell中使用curl(Invoke-WebRequest)
- [原创]在PowerShell中实现Ruby字符串类型方法swapcase
- 在PowerShell中调用C#代码创建对象类型
- 在hibernate中持久化枚举类型
- 枚举类型在游戏中实战应用
- 枚举类型在组合数据的使用
- 在枚举中使用位移
- 在C语言中函数中使用枚举类型和结构
- ProGuard详解
- Velocity模板引擎下 velocity.properties转义(转码)配置
- Android使用UncaughtExceptionHandler捕获全局异常
- Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled
- swift设置UIButton的title文字
- 在PowerShell中使用枚举类型
- Android native和h5混合开发几种常见的hybrid通信方式
- VMware Workstation cannot connect to the virtual machine
- Android中Build Target,minSdkVersitarget,targetSdkversion概念
- Generative Modeling of Convolutional Neural Networks,生成式CNNs
- Xcode删除所有断点
- 几种排序方式
- python中list操作详解
- Android Rectange Button的使用