在哪里可以找到 Powershell .NET 类型加速器的列表?

发布于 2024-07-27 18:31:19 字数 130 浏览 8 评论 0 原文

在 PowerShell 中,您可以使用 [xml] 来表示 [System.Xml.XmlDocument]。 您知道在哪里可以找到这些类型加速器的列表吗?

这些加速器是特定于 PowerShell 或 .NET 的吗?

In PowerShell you can use [xml] to mean [System.Xml.XmlDocument]. Do you know where I can find a list of these type accelerators?

Are these accelerators specific to PowerShell or .NET?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

烙印 2024-08-03 18:31:19

自从四年前提出并回答这个问题以来,PowerShell 一直在不断发展。 不幸的是,@KeithHill 的简洁答案不再有效。 我做了一些挖掘,发现必需的课程暴露得有点少。 好的一面是,类型加速器列表现在可以仅使用这一行代码来显示......

[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::Get

归因于 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

Since this question was asked and answered four years ago PowerShell has continued to evolve. @KeithHill's concise answer unfortunately no longer works. I did a little digging and found that the requisite class is just a bit less exposed. On the bright side, the list of type accelerators may now be displayed with just this one line of code...

[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::Get

... attributed to Jaykul in this Connect post.

Here is a partial output:

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 Update

As of PowerShell Community Extensions (PSCX) version 3.1.0, you can now use a type accelerator to list all type accelerators and just invoke this:

[accelerators]::get
以歌曲疗慰 2024-08-03 18:31:19

最终的方法是执行 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
...

请注意,您必须将新的“accelerators”加速器添加到字典中,因为 TypeAccelerators 类型不是公共的。 使用 .NET Reflector 和大量的业余时间可以做很多令人惊奇的事情。 :-) 你摇滚 Oisin!

The definitive way is to do what Oisin demontrates in this 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
...

Note that you have to add the new 'accelerators' accelerator to the dictionary because the TypeAccelerators type is not public. Amazing what you can do with .NET Reflector and a lot of spare time. :-) You rock Oisin!

執念 2024-08-03 18:31:19

请参阅 这篇博文。 我相信这是别名的完整列表。

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[]

See the section entitled Type Name Aliases in this blog post. I believe this is a complete list of the aliases.

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[]
深爱成瘾 2024-08-03 18:31:19

@诺尔多林有一些类型加速器的详细列表,其中有一些。

PowerShell 还允许您使用类型文字来转换对象、调用静态方法、访问静态属性、反射以及您可能对 System.Type 对象的实例执行的任何其他操作。

为了使用类型文字,您只需将类(或结构或枚举)的全名(命名空间和类名)(用句点分隔命名空间和类名)括在方括号中,例如:

[System.Net.NetworkInformation.IPStatus]

PowerShell 还将提供领先的“系统”。 尝试解析名称,因此如果您在 System* 命名空间中使用某些内容,则无需显式使用该名称。

[Net.NetworkInformation.IPStatus]

Oisin Grehan(PowerShell MVP)也有一篇关于创建自己的类型加速器的博客文章

@Noldorin has a good list of some of the Type Accelerators, with some.

PowerShell also allows you to use type literals to cast objects, call static methods, access static properties, reflect over, and anything else you might do with an instance of a System.Type object.

In order to use a type literal, you just enclose the full name (namespace and class name) of the class (or struct or enum) (with a period separating the namespace and the class name) enclosed in brackets like:

[System.Net.NetworkInformation.IPStatus]

PowerShell will also provide a leading "System." in its attempt to resolve the name, so you don't need to explicitly use that if you are using something in a System* namespace.

[Net.NetworkInformation.IPStatus]

Oisin Grehan (a PowerShell MVP) also has a blog post about creating your own type accelerators.

断肠人 2024-08-03 18:31:19

这是一个更完整的列表:

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

Here is a more complete list:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文