|
1 | 1 | --- |
2 | | -description: Describes the Type accelerators available for .NET framework classes |
| 2 | +description: Describes the type accelerators available for .NET types. |
3 | 3 | Locale: en-US |
4 | | -ms.date: 08/30/2023 |
| 4 | +ms.date: 01/21/2025 |
5 | 5 | online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_type_accelerators?view=powershell-7.4&WT.mc_id=ps-gethelp |
6 | 6 | schema: 2.0.0 |
7 | 7 | title: about_Type_Accelerators |
8 | 8 | --- |
9 | 9 | # about_Type_Accelerators |
10 | 10 |
|
11 | | -## SHORT DESCRIPTION |
12 | | -Describes the Type accelerators available for .NET framework classes |
| 11 | +## Short description |
| 12 | + |
| 13 | +Describes the type accelerators available for .NET types. |
13 | 14 |
|
14 | 15 | ## Long description |
15 | 16 |
|
16 | | -Type accelerators are aliases for .NET framework classes. They allow you to |
17 | | -access specific .NET framework classes without having to explicitly type the |
18 | | -entire class name. For example, you can shorten the **AliasAttribute** |
19 | | -class from `[System.Management.Automation.AliasAttribute]` to `[Alias]`. |
| 17 | +Type accelerators are aliases for .NET types. They allow you to access specific |
| 18 | +.NET types without explicitly using the full type name. For example, you can |
| 19 | +shorten `[System.Management.Automation.AliasAttribute]` to `[Alias]`. |
| 20 | + |
| 21 | +Type accelerator names are mostly lowercase, but some are defined using |
| 22 | +Pascal-case. PowerShell is case-insensitive, so you can use either. |
| 23 | + |
| 24 | +## Using type accelerators |
| 25 | + |
| 26 | +For most type accelerators, you use type accelerators in the same way as |
| 27 | +you would use the full type name. However, PowerShell has special handling for |
| 28 | +the following two type accelerators: |
| 29 | + |
| 30 | +- `pscustomobject` - See [about_PSCustomObject](about_PSCustomObject.md) |
| 31 | +- `ref` - See [about_Ref](about_Ref.md) |
| 32 | + |
| 33 | +Type accelerators are most commonly used to specify the type of a variable or |
| 34 | +cast an object to a specific type. For those cases, you must enclose the type |
| 35 | +name or its accelerator in square brackets (`[]`). For example, `[int]` or |
| 36 | +`[int32]`. |
| 37 | + |
| 38 | +In some contexts, you can specify allow type accelerator name as a string. For |
| 39 | +example: |
| 40 | + |
| 41 | +- When used with type comparison operators |
| 42 | + |
| 43 | + ```powershell |
| 44 | + PS> '1' -as 'int' |
| 45 | + 1 |
| 46 | + PS> 1 -is 'int' |
| 47 | + True |
| 48 | + ``` |
| 49 | + |
| 50 | +- When used with `[type]` type class |
| 51 | + |
| 52 | + ```powershell |
| 53 | + PS> [type]'int' |
| 54 | +
|
| 55 | + IsPublic IsSerial Name BaseType |
| 56 | + -------- -------- ---- -------- |
| 57 | + True True Int32 System.ValueType |
| 58 | + ``` |
20 | 59 |
|
21 | | -> [!NOTE] |
22 | | -> All type accelerators still need to be wrapped in square brackets(`[]`). |
| 60 | +In other contexts, like reflection, you must use the full type name as a string |
| 61 | +rather than the type accelerator name. |
23 | 62 |
|
24 | | -## Available Type Accelerators |
| 63 | +## Default type accelerators |
25 | 64 |
|
26 | | -| Accelerator | Full Class Name | |
| 65 | +| Accelerator name | Full type name | |
27 | 66 | | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | |
28 | 67 | | adsi | [System.DirectoryServices.DirectoryEntry](xref:System.DirectoryServices.DirectoryEntry) | |
29 | 68 | | adsisearcher | [System.DirectoryServices.DirectorySearcher](xref:System.DirectoryServices.DirectorySearcher) | |
@@ -66,6 +105,7 @@ class from `[System.Management.Automation.AliasAttribute]` to `[Alias]`. |
66 | 105 | | IPEndpoint | [System.Net.IPEndPoint](xref:System.Net.IPEndPoint) | |
67 | 106 | | long | [System.Int64](xref:System.Int64) | |
68 | 107 | | mailaddress | [System.Net.Mail.MailAddress](xref:System.Net.Mail.MailAddress) | |
| 108 | +| NoRunspaceAffinity | [System.Management.Automation.Language.NoRunspaceAffinityAttribute](xref:System.Management.Automation.Language.NoRunspaceAffinityAttribute) | |
69 | 109 | | NullString | [System.Management.Automation.Language.NullString](xref:System.Management.Automation.Language.NullString) | |
70 | 110 | | ObjectSecurity | [System.Security.AccessControl.ObjectSecurity](xref:System.Security.AccessControl.ObjectSecurity) | |
71 | 111 | | ordered | [System.Collections.Specialized.OrderedDictionary](xref:System.Collections.Specialized.OrderedDictionary) | |
@@ -115,6 +155,7 @@ class from `[System.Management.Automation.AliasAttribute]` to `[Alias]`. |
115 | 155 | | ValidateLength | [System.Management.Automation.ValidateLengthAttribute](xref:System.Management.Automation.ValidateLengthAttribute) | |
116 | 156 | | ValidateNotNull | [System.Management.Automation.ValidateNotNullAttribute](xref:System.Management.Automation.ValidateNotNullAttribute) | |
117 | 157 | | ValidateNotNullOrEmpty | [System.Management.Automation.ValidateNotNullOrEmptyAttribute](xref:System.Management.Automation.ValidateNotNullOrEmptyAttribute) | |
| 158 | +| ValidateNotNullOrWhiteSpace | [System.Management.Automation.ValidateNotNullOrWhiteSpaceAttribute](System.Management.Automation.ValidateNotNullOrWhiteSpaceAttribute) | |
118 | 159 | | ValidatePattern | [System.Management.Automation.ValidatePatternAttribute](xref:System.Management.Automation.ValidatePatternAttribute) | |
119 | 160 | | ValidateRange | [System.Management.Automation.ValidateRangeAttribute](xref:System.Management.Automation.ValidateRangeAttribute) | |
120 | 161 | | ValidateScript | [System.Management.Automation.ValidateScriptAttribute](xref:System.Management.Automation.ValidateScriptAttribute) | |
|
0 commit comments