Tys*_*tad 17 .net powershell types accelerator
在PowerShell中,您可以使用[xml]来表示[System.Xml.XmlDocument].你知道在哪里可以找到这些类型加速器的列表吗?
这些加速器是否特定于PowerShell或.NET?
Mic*_*ens 13
自从四年前提出并回答了这个问题以来,PowerShell一直在不断发展.不幸的是,@ KeithHill的简明回答不再有效.我做了一点挖掘,发现必需的类只是暴露了一点.在光明的一面,现在可以只用这种显示类型加速器的名单一个代码行...
[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::Get
Run Code Online (Sandbox Code Playgroud)
...在这篇Connect帖子中归因于Jaykul .
这是一个部分输出:
Key Value --- ----- Alias System.Management.Automation.AliasAttribute AllowEmptyCollection System.Management.Automation.AllowEmptyCollectionAttribute AllowEmptyString System.Management.Automation.AllowEmptyStringAttribute AllowNull System.Management.Automation.AllowNullAttribute array System.Array bool System.Boolean byte System.Byte char System.Char CmdletBinding System.Management.Automation.CmdletBindingAttribute datetime System.DateTime decimal System.Decimal adsi System.DirectoryServices.DirectoryEntry adsisearcher System.DirectoryServices.DirectorySearcher double System.Double float System.Single single System.Single guid System.Guid hashtable System.Collections.Hashtable int System.Int32 . . .
2014.03.15更新
从PowerShell社区扩展(PSCX)版本3.1.0开始,您现在可以使用类型加速器列出所有类型加速器并只调用它:
[accelerators]::get
Run Code Online (Sandbox Code Playgroud)
小智 12
明确的方法是在这篇优秀的博客文章中做Oisin贬低的事情:
PS> $acceleratorsType = [type]::gettype("System.Management.Automation.TypeAccelerators")
PS> $acceleratorsType
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
False False TypeAccelerators System.Object
PS> $acceleratorsType::Add("accelerators", $acceleratorsType)
PS> [accelerators]::Get
Key Value
--- -----
int System.Int32
...
Run Code Online (Sandbox Code Playgroud)
请注意,您必须将新的"加速器"加速器添加到字典中,因为TypeAccelerators类型不是公共的.令人惊讶的是你可以使用.NET Reflector和大量的业余时间.:-)你摇滚Oisin!
见标题为类型名称别名在这个博客帖子.我相信这是一个完整的别名列表.
PowerShell Type Alias Corresponding .NET Type [int] System.Int32 [int[]] System.Int32[] [long] System.Int64 [long[]] System.Int64[] [string] System.String [string[]] System.String[] [char] System.Char [char[]] System.Char[] [bool] System.Boolean [bool[]] System.Boolean[] [byte] System.Byte [byte[]] System.Byte[] [double] System.Double [double[]] System.Double[] [decimal] System.Decimal [decimal[]] System.Decimal[] [float] System.Single [single] System.Single [regex] System.Text.RegularExpression.Regex [array] System.Array [xml] System.Xml.XmlDocument [scriptblock] System.Management.Automation.ScriptBlock [switch] System.Management.Automation.SwitchParameter [hashtable] System.Collections.Hashtable [psobject] System.Management.Automation.PSObject [type] System.Type [type[]] System.Type[]
| 归档时间: |
|
| 查看次数: |
5744 次 |
| 最近记录: |