在PowerShell中,您可以指定带方括号的类型,如下所示:
PS C:\Users\zippy> [int]
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Int32 System.ValueType
Run Code Online (Sandbox Code Playgroud)
还有像[xml]这样的内置类型加速器,当您希望将某些内容转换为XmlDocument时,它会保存一些按键.
PS C:\Users\zippy> [xml]
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False XmlDocument System.Xml.XmlNode
Run Code Online (Sandbox Code Playgroud)
您可以通过以下两个命令之一生成列表:
[type]::gettype("System.Management.Automation.TypeAccelerators")::Get[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::GetPowerShell 3.0添加了一个名为[ordered]的运算符.它不是一个类型别名.
PS C:\Users\zippy> [ordered]
Unable to find type [ordered]: make sure that the assembly containing this type is loaded.
At line:1 char:1
+ [ordered]
+ ~~~~~~~~~
+ CategoryInfo : InvalidOperation: (ordered:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Run Code Online (Sandbox Code Playgroud)
但是,它可以将Hashtable转换为OrderedDictionary.
PS C:\Users\zippy> ([ordered]@{}).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True OrderedDictionary System.Object
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如果[ordered]不是类型加速器,它是什么?
不幸的[ordered]是有点失常。它既不是类型也不是加速器。它仅存在于解析器中,并被视为如何创建哈希表的提示(即不要使用哈希表,而是使用有序字典。)将其视为 .net 属性,但它不是 :D
| 归档时间: |
|
| 查看次数: |
1958 次 |
| 最近记录: |