18

PowerShell では、[xml] を使用して [System.Xml.XmlDocument] を意味できます。これらの型アクセラレータのリストがどこにあるか知っていますか?

これらのアクセラレータは、PowerShell または .NET に固有のものですか?

4

5 に答える 5

13

この質問と回答が 4 年前に出されて以来、PowerShell は進化を続けてきました。残念ながら、@ KeithHillの簡潔な答えは機能しなくなりました。少し掘り下げてみたところ、必要なクラスが少し公開されていないことがわかりました。明るい面としては、この1行のコードだけで型アクセラレータの一覧が表示されるようになった可能性があります...

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

... このConnect の投稿で Jaykul に帰属します。

部分的な出力を次に示します。

キー値
--- -----
エイリアス System.Management.Automation.AliasAttribute
AllowEmptyCollection System.Management.Automation.AllowEmptyCollectionAttribute
AllowEmptyString System.Management.Automation.AllowEmptyStringAttribute
AllowNull System.Management.Automation.AllowNullAttribute
配列 System.Array
bool System.Boolean
バイト System.Byte
char System.Char
CmdletBinding System.Management.Automation.CmdletBindingAttribute
日時 System.DateTime
小数 System.Decimal
adsi System.DirectoryServices.DirectoryEntry
adsisearcher System.DirectoryServices.DirectorySearcher
double System.Double
float System.Single
System.Single
GUID System.Guid
ハッシュテーブル System.Collections.Hashtable
int System.Int32
. . .

2014.03.15 更新

PowerShell Community Extensions (PSCX) バージョン 3.1.0の時点で、型アクセラレータを使用してすべての型アクセラレータを一覧表示し、これを呼び出すことができるようになりました。

[accelerators]::get
于 2013-06-05T19:08:45.060 に答える
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
...

TypeAccelerators タイプは公開されていないため、新しい「accelerators」アクセラレーターをディクショナリに追加する必要があることに注意してください。.NET Reflector と多くの空き時間でできることは驚くべきことです。:-) あなたは Oisin を揺るがします !

于 2009-07-18T19:59:23.223 に答える
8

このブログ投稿Type Name Aliasesというタイトルのセクションを参照してください。これがエイリアスの完全なリストだと思います。

PowerShell タイプ エイリアス 対応する .NET タイプ
[int] System.Int32
[int[]] System.Int32[]
[長い] System.Int64
[長い[]] System.Int64[]
[文字列] System.String
[文字列[]] System.String[]
[char] System.Char
[char[]] System.Char[]
[bool] System.Boolean
[bool[]] System.Boolean[]
[バイト] System.Byte
[バイト[]] System.Byte[]
[ダブル] System.Double
[ダブル[]] System.Double[]
[10 進数] System.Decimal
[小数[]] System.Decimal[]
[float] System.Single
[シングル] System.Single
[正規表現] System.Text.RegularExpression.Regex
[配列] System.Array
[xml] System.Xml.XmlDocument
[スクリプトブロック] System.Management.Automation.ScriptBlock
[スイッチ] System.Management.Automation.SwitchParameter
[ハッシュテーブル] System.Collections.Hashtable
[psobject] System.Management.Automation.PSObject
[タイプ] System.Type
[タイプ[]] System.Type[]
于 2009-07-17T20:01:18.957 に答える
3

@ Noldorinには、いくつかのタイプ アクセラレータの優れたリストがあります。

PowerShell では、型リテラルを使用して、オブジェクトのキャスト、静的メソッドの呼び出し、静的プロパティへのアクセス、リフレクト オーバー、および System.Type オブジェクトのインスタンスで行う可能性のあるその他の操作を行うこともできます。

型リテラルを使用するには、クラス (または構造体または列挙型) の完全な名前 (名前空間とクラス名) を (名前空間とクラス名をピリオドで区切って) 次のように角かっこで囲みます。

[System.Net.NetworkInformation.IPStatus]

PowerShell は、最先端の「システム」も提供します。そのため、System* 名前空間で何かを使用している場合は、明示的に使用する必要はありません。

[Net.NetworkInformation.IPStatus]

Oisin Grehan (PowerShell MVP) も、独自の型アクセラレータの作成に関するブログ投稿を行っています

于 2009-07-17T22:35:08.977 に答える
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
于 2016-04-11T19:20:13.677 に答える