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?
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?
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[]
@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.
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!