在PowerShell中,您可以使用[xml]表示[System.Xml.XmlDocument]。你知道我在哪里可以找到这些类型加速器的列表吗?
这些加速器是否特定于PowerShell或.NET?
答案 0 :(得分:13)
自从四年前提出并回答了这个问题以来,PowerShell一直在不断发展。不幸的是,@ KeithHill的简明回答不再有效。我做了一点挖掘,发现必需的类只是暴露了一点。从好的方面来看,现在可以使用一个代码行显示类型加速器列表......
[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::Get
...在Connect post中归因于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 Community Extensions(PSCX)版本3.1.0开始,您现在可以使用类型加速器列出所有类型加速器并只调用它:
[accelerators]::get
答案 1 :(得分:12)
明确的方法是做Oisin在这个excellent blog post中诋毁的事情:
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
...
请注意,您必须将新的“加速器”加速器添加到字典中,因为TypeAccelerators类型不是公共的。令人惊讶的是你可以使用.NET Reflector和大量的业余时间。 :-)你摇滚Oisin!
答案 2 :(得分:7)
请参阅this blog post中标题为类型名称别名的部分。我相信这是一个完整的别名列表。
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[]
答案 3 :(得分:3)
@ Noldorin有一些类型加速器的好列表,有些。
PowerShell还允许您使用类型文字来转换对象,调用静态方法,访问静态属性,反映以及您可能对System.Type对象的实例执行的任何其他操作。
为了使用类型文字,您只需将类(或结构或枚举)的全名(名称空间和类名)(括在命名空间和类名称之间)括在括号中,如:< / p>
[System.Net.NetworkInformation.IPStatus]
PowerShell还将提供领先的“系统”。在尝试解析名称时,如果您在System *名称空间中使用某些东西,则不需要显式使用它。
[Net.NetworkInformation.IPStatus]
Oisin Grehan (a PowerShell MVP) also has a blog post about creating your own type accelerators
答案 4 :(得分:1)
这是一个更完整的清单:
Key Value
--- -----
adsi System.DirectoryServices.DirectoryEntry
adsisearcher System.DirectoryServices.DirectorySearcher
array System.Array
bigint System.Numerics.BigInteger
bool System.Boolean
byte System.Byte
char System.Char
cimclass Microsoft.Management.Infrastructure.CimClass
cimconverter Microsoft.Management.Infrastructure.CimConverter
ciminstance Microsoft.Management.Infrastructure.CimInstance
cimtype Microsoft.Management.Infrastructure.CimType
cultureinfo System.Globalization.CultureInfo
datetime System.DateTime
decimal System.Decimal
double System.Double
float System.Single
guid System.Guid
hashtable System.Collections.Hashtable
initialsessionstate System.Management.Automation.Runspaces.InitialSessionState
int System.Int32
int16 System.Int16
int32 System.Int32
int64 System.Int64
ipaddress System.Net.IPAddress
long System.Int64
mailaddress System.Net.Mail.MailAddress
powershell System.Management.Automation.PowerShell
psaliasproperty System.Management.Automation.PSAliasProperty
pscredential System.Management.Automation.PSCredential
pscustomobject System.Management.Automation.PSObject
pslistmodifier System.Management.Automation.PSListModifier
psmoduleinfo System.Management.Automation.PSModuleInfo
psnoteproperty System.Management.Automation.PSNoteProperty
psobject System.Management.Automation.PSObject
psprimitivedictionary System.Management.Automation.PSPrimitiveDictionary
psscriptmethod System.Management.Automation.PSScriptMethod
psscriptproperty System.Management.Automation.PSScriptProperty
psvariable System.Management.Automation.PSVariable
psvariableproperty System.Management.Automation.PSVariableProperty
ref System.Management.Automation.PSReference
regex System.Text.RegularExpressions.Regex
runspace System.Management.Automation.Runspaces.Runspace
runspacefactory System.Management.Automation.Runspaces.RunspaceFactory
sbyte System.SByte
scriptblock System.Management.Automation.ScriptBlock
securestring System.Security.SecureString
single System.Single
string System.String
switch System.Management.Automation.SwitchParameter
timespan System.TimeSpan
type System.Type
uint16 System.UInt16
uint32 System.UInt32
uint64 System.UInt64
uri System.Uri
version System.Version
void System.Void
wmi System.Management.ManagementObject
wmiclass System.Management.ManagementClass
wmisearcher System.Management.ManagementObjectSearcher
xml System.Xml.XmlDocument