В PowerShell вы можете использовать [xml] для обозначения [System.Xml.XmlDocument]. Вы знаете, где я могу найти список ускорителей этого типа?
Являются ли эти ускорители конкретными для PowerShell или .NET?
В PowerShell вы можете использовать [xml] для обозначения [System.Xml.XmlDocument]. Вы знаете, где я могу найти список ускорителей этого типа?
Являются ли эти ускорители конкретными для PowerShell или .NET?
См. раздел "Алиасы имен типов" в этот пост в блоге. Я считаю, что это полный список псевдонимов.
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[]
Определенный способ - сделать то, что 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 не является общедоступным. Удивительно, что вы можете делать с .NET Reflector и много свободного времени.:-) Вы качаете Oisin!
Поскольку этот вопрос задавали и отвечали четыре года назад, PowerShell продолжал развиваться. @KeithHill краткий ответ, к сожалению, больше не работает. Я немного погубился и обнаружил, что необходимый класс чуть менее разоблачен. С яркой стороны список ускорителей типов теперь может отображаться только с этой одной строкой кода...
[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::Get
... приписывается Jaykul в этом Connect post.
Вот частичный вывод:
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
@Noldorin имеет хороший список некоторых ускорителей типа, с некоторыми.
PowerShell также позволяет использовать литералы типов для создания объектов, вызова статических методов, доступа к статическим свойствам, отражения и любого другого, что вы можете сделать с экземпляром объекта System.Type.
Чтобы использовать литерал типа, вы просто заключаете полное имя (пространство имен и имя класса) класса (или структуры или перечисления) (с периодом, разделяющим пространство имен и имя класса), заключенным в скобки, например:
[System.Net.NetworkInformation.IPStatus]
PowerShell также предоставит ведущую "Систему". в попытке разрешить имя, поэтому вам не нужно явно использовать это, если вы используете что-то в пространстве имен System *.
[Net.NetworkInformation.IPStatus]
Oisin Grehan (PowerShell MVP) также имеет сообщение в блоге о создании собственных ускорителей типов.
Вот более полный список:
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