From 472569ccc11d4c36f2d7b1ad13eabd053d513167 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Thu, 22 Jan 2026 10:28:03 -0600 Subject: [PATCH 1/4] Update description of instantiation syntax --- .../About/about_Classes.md | 77 +++++++++++++++--- .../About/about_Classes.md | 79 ++++++++++++++++--- .../About/about_Classes.md | 79 ++++++++++++++++--- .../About/about_Classes.md | 79 ++++++++++++++++--- 4 files changed, 275 insertions(+), 39 deletions(-) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md index f88896937c50..a119537c1033 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md @@ -1,7 +1,7 @@ --- description: Describes how you can use classes to create your own custom types. Locale: en-US -ms.date: 01/19/2024 +ms.date: 01/22/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Classes @@ -64,18 +64,17 @@ To instantiate an instance of a class, use one of the following syntaxes: ``` ```Syntax -[$ =] []@{[]} +[$ =] [] ``` > [!NOTE] > When using the `[]::new()` syntax, brackets around the class name > are mandatory. The brackets signal a type definition for PowerShell. > -> The hashtable syntax only works for classes that have a default constructor -> that doesn't expect any parameters. It creates an instance of the class with -> the default constructor and then assigns the key-value pairs to the instance -> properties. If any key in the hashtable isn't a valid property name, -> PowerShell raises an error. +> The `` syntax only works for classes that have a +> default constructor that doesn't expect any parameters. It creates an +> instance of the class with the default constructor and then uses runtime type +> conversion to assign the values provided. ## Examples @@ -99,7 +98,67 @@ Brand Fabrikam, Inc. ``` -### Example 2 - Class with instance members +### Example 2 - Using instantiation syntax + +This example defines a **Book** class with several properties, but no +constructor. + +```powershell +class Book { + # Class properties + [string] $Title + [string] $Author + [string] $Synopsis + [string] $Publisher + [datetime] $PublishDate + [int] $PageCount + [string[]] $Tags +} +``` + +The following example shows how the default constructor can assign the values +of a compatible using type coercion. In this example, a hashtable is used to +provide the property values. + +```powershell +$Book1 = [Book] @{ + Title = '1984' + Author = 'George Orwell' + Synopsis = '' + Publisher = 'Secker & Warburg' + PublishDate = '1949-06-08' + PageCount = 328 + Tags = @('Dystopian', 'Political Fiction', 'Social Science Fiction') +} +$Book1 +``` + +```Output +Title : 1984 +Author : George Orwell +Synopsis : +Publisher : Secker & Warburg +PublishDate : 6/8/1949 12:00:00 AM +PageCount : 328 +Tags : {Dystopian, Political Fiction, Social Science Fiction} +``` + +The key-value pairs of the hashtable are assigned to the instance properties. +If any key in the hashtable isn't a valid property name, instantiation fails. + +In this example, an array is used to provide the values for the generic list. + +```powershell +$List = [System.Collections.Generic.List[int]] @(42, 43) +$List +``` + +```Output +42 +43 +``` + +### Example 3 - Class with instance members This example defines a **Book** class with several properties, constructors, and methods. Every defined member is an _instance_ member, not a static member. @@ -190,7 +249,7 @@ It takes 10 hours and 20 minutes to read The Hobbit by J.R.R. Tolkien (1937), which was published 86 years ago. ``` -### Example 3 - Class with static members +### Example 4 - Class with static members The **BookList** class in this example builds on the **Book** class in example 2. While the **BookList** class can't be marked static itself, the diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md index 28e2fd792341..290de8d93b9f 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md @@ -1,7 +1,7 @@ --- description: Describes how you can use classes to create your own custom types. Locale: en-US -ms.date: 01/23/2024 +ms.date: 01/22/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Classes @@ -64,18 +64,17 @@ To instantiate an instance of a class, use one of the following syntaxes: ``` ```Syntax -[$ =] []@{[]} +[$ =] [] ``` > [!NOTE] > When using the `[]::new()` syntax, brackets around the class name > are mandatory. The brackets signal a type definition for PowerShell. > -> The hashtable syntax only works for classes that have a default constructor -> that doesn't expect any parameters. It creates an instance of the class with -> the default constructor and then assigns the key-value pairs to the instance -> properties. If any key in the hashtable isn't a valid property name, -> PowerShell raises an error. +> The `` syntax only works for classes that have a +> default constructor that doesn't expect any parameters. It creates an +> instance of the class with the default constructor and then uses runtime type +> conversion to assign the values provided. ## Examples @@ -99,7 +98,67 @@ Brand Fabrikam, Inc. ``` -### Example 2 - Class with instance members +### Example 2 - Using instantiation syntax + +This example defines a **Book** class with several properties, but no +constructor. + +```powershell +class Book { + # Class properties + [string] $Title + [string] $Author + [string] $Synopsis + [string] $Publisher + [datetime] $PublishDate + [int] $PageCount + [string[]] $Tags +} +``` + +The following example shows how the default constructor can assign the values +of a compatible using type coercion. In this example, a hashtable is used to +provide the property values. + +```powershell +$Book1 = [Book] @{ + Title = '1984' + Author = 'George Orwell' + Synopsis = '' + Publisher = 'Secker & Warburg' + PublishDate = '1949-06-08' + PageCount = 328 + Tags = @('Dystopian', 'Political Fiction', 'Social Science Fiction') +} +$Book1 +``` + +```Output +Title : 1984 +Author : George Orwell +Synopsis : +Publisher : Secker & Warburg +PublishDate : 6/8/1949 12:00:00 AM +PageCount : 328 +Tags : {Dystopian, Political Fiction, Social Science Fiction} +``` + +The key-value pairs of the hashtable are assigned to the instance properties. +If any key in the hashtable isn't a valid property name, instantiation fails. + +In this example, an array is used to provide the values for the generic list. + +```powershell +$List = [System.Collections.Generic.List[int]] @(42, 43) +$List +``` + +```Output +42 +43 +``` + +### Example 3 - Class with instance members This example defines a **Book** class with several properties, constructors, and methods. Every defined member is an _instance_ member, not a static member. @@ -190,7 +249,7 @@ It takes 10 hours and 20 minutes to read The Hobbit by J.R.R. Tolkien (1937), which was published 86 years ago. ``` -### Example 3 - Class with static members +### Example 4 - Class with static members The **BookList** class in this example builds on the **Book** class in example 2. While the **BookList** class can't be marked static itself, the @@ -360,7 +419,7 @@ Line | | Book 'The Hobbit by J.R.R. Tolkien (1937)' already in list ``` -### Example 4 - Class definition with and without Runspace affinity +### Example 5 - Class definition with and without Runspace affinity The `ShowRunspaceId()` method of `[UnsafeClass]` reports different thread Ids but the same runspace ID. Eventually, the session state is corrupted causing diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md index 5eed77c25f46..619464f28a74 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md @@ -1,7 +1,7 @@ --- description: Describes how you can use classes to create your own custom types. Locale: en-US -ms.date: 01/23/2024 +ms.date: 01/22/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.5&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Classes @@ -64,18 +64,17 @@ To instantiate an instance of a class, use one of the following syntaxes: ``` ```Syntax -[$ =] []@{[]} +[$ =] [] ``` > [!NOTE] > When using the `[]::new()` syntax, brackets around the class name > are mandatory. The brackets signal a type definition for PowerShell. > -> The hashtable syntax only works for classes that have a default constructor -> that doesn't expect any parameters. It creates an instance of the class with -> the default constructor and then assigns the key-value pairs to the instance -> properties. If any key in the hashtable isn't a valid property name, -> PowerShell raises an error. +> The `` syntax only works for classes that have a +> default constructor that doesn't expect any parameters. It creates an +> instance of the class with the default constructor and then uses runtime type +> conversion to assign the values provided. ## Examples @@ -99,7 +98,67 @@ Brand Fabrikam, Inc. ``` -### Example 2 - Class with instance members +### Example 2 - Using instantiation syntax + +This example defines a **Book** class with several properties, but no +constructor. + +```powershell +class Book { + # Class properties + [string] $Title + [string] $Author + [string] $Synopsis + [string] $Publisher + [datetime] $PublishDate + [int] $PageCount + [string[]] $Tags +} +``` + +The following example shows how the default constructor can assign the values +of a compatible using type coercion. In this example, a hashtable is used to +provide the property values. + +```powershell +$Book1 = [Book] @{ + Title = '1984' + Author = 'George Orwell' + Synopsis = '' + Publisher = 'Secker & Warburg' + PublishDate = '1949-06-08' + PageCount = 328 + Tags = @('Dystopian', 'Political Fiction', 'Social Science Fiction') +} +$Book1 +``` + +```Output +Title : 1984 +Author : George Orwell +Synopsis : +Publisher : Secker & Warburg +PublishDate : 6/8/1949 12:00:00 AM +PageCount : 328 +Tags : {Dystopian, Political Fiction, Social Science Fiction} +``` + +The key-value pairs of the hashtable are assigned to the instance properties. +If any key in the hashtable isn't a valid property name, instantiation fails. + +In this example, an array is used to provide the values for the generic list. + +```powershell +$List = [System.Collections.Generic.List[int]] @(42, 43) +$List +``` + +```Output +42 +43 +``` + +### Example 3 - Class with instance members This example defines a **Book** class with several properties, constructors, and methods. Every defined member is an _instance_ member, not a static member. @@ -190,7 +249,7 @@ It takes 10 hours and 20 minutes to read The Hobbit by J.R.R. Tolkien (1937), which was published 86 years ago. ``` -### Example 3 - Class with static members +### Example 4 - Class with static members The **BookList** class in this example builds on the **Book** class in example 2. While the **BookList** class can't be marked static itself, the @@ -360,7 +419,7 @@ Line | | Book 'The Hobbit by J.R.R. Tolkien (1937)' already in list ``` -### Example 4 - Class definition with and without Runspace affinity +### Example 5 - Class definition with and without Runspace affinity The `ShowRunspaceId()` method of `[UnsafeClass]` reports different thread Ids but the same runspace ID. Eventually, the session state is corrupted causing diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md index 713e4c76d07c..0478cf4476d3 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md @@ -1,7 +1,7 @@ --- description: Describes how you can use classes to create your own custom types. Locale: en-US -ms.date: 01/23/2024 +ms.date: 01/22/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.6&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Classes @@ -64,18 +64,17 @@ To instantiate an instance of a class, use one of the following syntaxes: ``` ```Syntax -[$ =] []@{[]} +[$ =] [] ``` > [!NOTE] > When using the `[]::new()` syntax, brackets around the class name > are mandatory. The brackets signal a type definition for PowerShell. > -> The hashtable syntax only works for classes that have a default constructor -> that doesn't expect any parameters. It creates an instance of the class with -> the default constructor and then assigns the key-value pairs to the instance -> properties. If any key in the hashtable isn't a valid property name, -> PowerShell raises an error. +> The `` syntax only works for classes that have a +> default constructor that doesn't expect any parameters. It creates an +> instance of the class with the default constructor and then uses runtime type +> conversion to assign the values provided. ## Examples @@ -99,7 +98,67 @@ Brand Fabrikam, Inc. ``` -### Example 2 - Class with instance members +### Example 2 - Using instantiation syntax + +This example defines a **Book** class with several properties, but no +constructor. + +```powershell +class Book { + # Class properties + [string] $Title + [string] $Author + [string] $Synopsis + [string] $Publisher + [datetime] $PublishDate + [int] $PageCount + [string[]] $Tags +} +``` + +The following example shows how the default constructor can assign the values +of a compatible using type coercion. In this example, a hashtable is used to +provide the property values. + +```powershell +$Book1 = [Book] @{ + Title = '1984' + Author = 'George Orwell' + Synopsis = '' + Publisher = 'Secker & Warburg' + PublishDate = '1949-06-08' + PageCount = 328 + Tags = @('Dystopian', 'Political Fiction', 'Social Science Fiction') +} +$Book1 +``` + +```Output +Title : 1984 +Author : George Orwell +Synopsis : +Publisher : Secker & Warburg +PublishDate : 6/8/1949 12:00:00 AM +PageCount : 328 +Tags : {Dystopian, Political Fiction, Social Science Fiction} +``` + +The key-value pairs of the hashtable are assigned to the instance properties. +If any key in the hashtable isn't a valid property name, instantiation fails. + +In this example, an array is used to provide the values for the generic list. + +```powershell +$List = [System.Collections.Generic.List[int]] @(42, 43) +$List +``` + +```Output +42 +43 +``` + +### Example 3 - Class with instance members This example defines a **Book** class with several properties, constructors, and methods. Every defined member is an _instance_ member, not a static member. @@ -190,7 +249,7 @@ It takes 10 hours and 20 minutes to read The Hobbit by J.R.R. Tolkien (1937), which was published 86 years ago. ``` -### Example 3 - Class with static members +### Example 4 - Class with static members The **BookList** class in this example builds on the **Book** class in example 2. While the **BookList** class can't be marked static itself, the @@ -360,7 +419,7 @@ Line | | Book 'The Hobbit by J.R.R. Tolkien (1937)' already in list ``` -### Example 4 - Class definition with and without Runspace affinity +### Example 5 - Class definition with and without Runspace affinity The `ShowRunspaceId()` method of `[UnsafeClass]` reports different thread Ids but the same runspace ID. Eventually, the session state is corrupted causing From d16795f662536020dd8859992a6dd174d225e286 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Thu, 22 Jan 2026 10:51:42 -0600 Subject: [PATCH 2/4] Fix link references --- .../About/about_Classes.md | 81 +++++++++-------- .../About/about_Classes.md | 89 +++++++++---------- .../About/about_Classes.md | 89 +++++++++---------- .../About/about_Classes.md | 89 +++++++++---------- 4 files changed, 172 insertions(+), 176 deletions(-) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md index a119537c1033..4e6b0f1af288 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md @@ -251,10 +251,10 @@ which was published 86 years ago. ### Example 4 - Class with static members -The **BookList** class in this example builds on the **Book** class in example -2. While the **BookList** class can't be marked static itself, the -implementation only defines the **Books** static property and a set of static -methods for managing that property. +The **BookList** class in this example builds on the **Book** class in the +previous example. While the **BookList** class can't be marked static itself, +the implementation only defines the **Books** static property and a set of +static methods for managing that property. ```powershell class BookList { @@ -428,7 +428,7 @@ Properties are variables declared in the class scope. A property can be of any built-in type or an instance of another class. Classes can have zero or more properties. Classes don't have a maximum property count. -For more information, see [about_Classes_Properties][01]. +For more information, see [about_Classes_Properties][10]. ## Class methods @@ -438,7 +438,7 @@ method doesn't return any output, it must have the **Void** output type. If a method doesn't explicitly define an output type, the method's output type is **Void**. -For more information, see [about_Classes_Methods][02]. +For more information, see [about_Classes_Methods][05]. ## Class constructors @@ -447,7 +447,7 @@ moment of creating the instance of the class. Constructors have the same name as the class. Constructors might have parameters, to initialize the data members of the new object. -For more information, see [about_Classes_Constructors][03]. +For more information, see [about_Classes_Constructors][01]. ## Hidden keyword @@ -476,11 +476,11 @@ Hidden class members are: > When you hide any constructor, the `new()` option is removed from > IntelliSense and completion results. -For more information about the keyword, see [about_Hidden][04]. For more -information about hidden properties, see [about_Classes_Properties][05]. For +For more information about the keyword, see [about_Hidden][12]. For more +information about hidden properties, see [about_Classes_Properties][09]. For more information about hidden methods, see [about_Classes_Methods][06]. For more information about hidden constructors, see -[about_Classes_Constructors][07]. +[about_Classes_Constructors][02]. ## Static keyword @@ -494,9 +494,9 @@ available always. All static properties live for the entire session span. The `static` keyword only applies to class members, not a class itself. For more information about static properties, see -[about_Classes_Properties][08]. For more information about static methods, see -[about_Classes_Methods][09]. For more information about static constructors, -see [about_Classes_Constructors][10]. +[about_Classes_Properties][10]. For more information about static methods, see +[about_Classes_Methods][07]. For more information about static constructors, +see [about_Classes_Constructors][03]. ## Inheritance in PowerShell classes @@ -512,8 +512,7 @@ inherits from an interface must implement that contract. When it does, the class can be used like any other class implementing that interface. For more information about deriving classes that inherit from a base class or -implement interfaces, see -[about_Classes_Inheritance][11]. +implement interfaces, see [about_Classes_Inheritance][04]. ## Export classes with type accelerators @@ -599,7 +598,7 @@ consistently import classes defined in nested modules or classes defined in scripts that are dot-sourced into the root module. Define classes that you want to be available to users outside of the module directly in the root module. -For more information about the `using` statement, see [about_Using][12]. +For more information about the `using` statement, see [about_Using][15]. ## Load newly changed code during development @@ -626,7 +625,7 @@ parameters can't be used with class members. The **PSReference** class was designed to support COM objects. COM objects have cases where you need to pass a value in by reference. -For more information, see [PSReference Class][13]. +For more information, see [PSReference Class][16]. ## Limitations @@ -740,30 +739,30 @@ workaround for those limitations, if any. ## See also -- [about_Classes_Constructors][03] -- [about_Classes_Inheritance][11] -- [about_Classes_Methods][02] -- [about_Classes_Properties][01] -- [about_Enum][14] -- [about_Hidden][04] -- [about_Language_Keywords][15] -- [about_Methods][16] -- [about_Using][12] +- [about_Classes_Constructors][01] +- [about_Classes_Inheritance][04] +- [about_Classes_Methods][05] +- [about_Classes_Properties][08] +- [about_Enum][11] +- [about_Hidden][12] +- [about_Language_Keywords][13] +- [about_Methods][14] +- [about_Using][15] -[01]: about_Classes_Properties.md -[02]: about_Classes_Methods.md -[03]: about_Classes_Constructors.md -[04]: about_Hidden.md -[05]: about_Classes_Properties.md#hidden-properties +[01]: about_Classes_Constructors.md +[02]: about_Classes_Constructors.md#hidden-constructors +[03]: about_Classes_Constructors.md#static-constructors +[04]: about_Classes_Inheritance.md +[05]: about_Classes_Methods.md [06]: about_Classes_Methods.md#hidden-methods -[07]: about_Classes_Constructors.md#hidden-constructors -[08]: about_Classes_Properties.md#static-properties -[09]: about_Classes_Methods.md#static-methods -[10]: about_Classes_Constructors.md#static-constructors -[11]: about_Classes_Inheritance.md -[12]: about_Using.md -[13]: /dotnet/api/system.management.automation.psreference -[14]: about_Enum.md -[15]: about_language_keywords.md -[16]: about_methods.md +[07]: about_Classes_Methods.md#static-methods +[08]: about_Classes_Properties.md +[09]: about_Classes_Properties.md#hidden-properties +[10]: about_Classes_Properties.md#static-properties +[11]: about_Enum.md +[12]: about_Hidden.md +[13]: about_language_keywords.md +[14]: about_methods.md +[15]: about_Using.md +[16]: xref:System.Management.Automation.PSReference diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md index 290de8d93b9f..fe21c7f26690 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md @@ -251,10 +251,10 @@ which was published 86 years ago. ### Example 4 - Class with static members -The **BookList** class in this example builds on the **Book** class in example -2. While the **BookList** class can't be marked static itself, the -implementation only defines the **Books** static property and a set of static -methods for managing that property. +The **BookList** class in this example builds on the **Book** class in the +previous example. While the **BookList** class can't be marked static itself, +the implementation only defines the **Books** static property and a set of +static methods for managing that property. ```powershell class BookList { @@ -485,7 +485,7 @@ Properties are variables declared in the class scope. A property can be of any built-in type or an instance of another class. Classes can have zero or more properties. Classes don't have a maximum property count. -For more information, see [about_Classes_Properties][01]. +For more information, see [about_Classes_Properties][09]. ## Class methods @@ -495,7 +495,7 @@ method doesn't return any output, it must have the **Void** output type. If a method doesn't explicitly define an output type, the method's output type is **Void**. -For more information, see [about_Classes_Methods][02]. +For more information, see [about_Classes_Methods][06]. ## Class constructors @@ -504,7 +504,7 @@ moment of creating the instance of the class. Constructors have the same name as the class. Constructors might have parameters, to initialize the data members of the new object. -For more information, see [about_Classes_Constructors][03]. +For more information, see [about_Classes_Constructors][02]. ## Hidden keyword @@ -533,11 +533,11 @@ Hidden class members are: > When you hide any constructor, the `new()` option is removed from > IntelliSense and completion results. -For more information about the keyword, see [about_Hidden][04]. For more -information about hidden properties, see [about_Classes_Properties][05]. For -more information about hidden methods, see [about_Classes_Methods][06]. For +For more information about the keyword, see [about_Hidden][13]. For more +information about hidden properties, see [about_Classes_Properties][10]. For +more information about hidden methods, see [about_Classes_Methods][07]. For more information about hidden constructors, see -[about_Classes_Constructors][07]. +[about_Classes_Constructors][03]. ## Static keyword @@ -551,9 +551,9 @@ available always. All static properties live for the entire session span. The `static` keyword only applies to class members, not a class itself. For more information about static properties, see -[about_Classes_Properties][08]. For more information about static methods, see -[about_Classes_Methods][09]. For more information about static constructors, -see [about_Classes_Constructors][10]. +[about_Classes_Properties][11]. For more information about static methods, see +[about_Classes_Methods][08]. For more information about static constructors, +see [about_Classes_Constructors][04]. ## Inheritance in PowerShell classes @@ -569,8 +569,7 @@ inherits from an interface must implement that contract. When it does, the class can be used like any other class implementing that interface. For more information about deriving classes that inherit from a base class or -implement interfaces, see -[about_Classes_Inheritance][11]. +implement interfaces, see [about_Classes_Inheritance][05]. ## NoRunspaceAffinity attribute @@ -592,8 +591,7 @@ thread and the thread's current session state. The attribute was added in PowerShell 7.4. For an illustration of the difference in behavior for classes with and without -the `NoRunspaceAffinity` attribute, see -[Example 4](#example-4---class-definition-with-and-without-runspace-affinity). +the `NoRunspaceAffinity` attribute, see [Example 5][01]. ## Export classes with type accelerators @@ -679,7 +677,7 @@ consistently import classes defined in nested modules or classes defined in scripts that are dot-sourced into the root module. Define classes that you want to be available to users outside of the module directly in the root module. -For more information about the `using` statement, see [about_Using][12]. +For more information about the `using` statement, see [about_Using][16]. ## Load newly changed code during development @@ -706,7 +704,7 @@ parameters can't be used with class members. The **PSReference** class was designed to support COM objects. COM objects have cases where you need to pass a value in by reference. -For more information, see [PSReference Class][13]. +For more information, see [PSReference Class][17]. ## Limitations @@ -826,30 +824,31 @@ workaround for those limitations, if any. ## See also -- [about_Classes_Constructors][03] -- [about_Classes_Inheritance][11] -- [about_Classes_Methods][02] -- [about_Classes_Properties][01] -- [about_Enum][14] -- [about_Hidden][04] -- [about_Language_Keywords][15] -- [about_Methods][16] -- [about_Using][12] +- [about_Classes_Constructors][02] +- [about_Classes_Inheritance][05] +- [about_Classes_Methods][06] +- [about_Classes_Properties][09] +- [about_Enum][12] +- [about_Hidden][13] +- [about_Language_Keywords][14] +- [about_Methods][15] +- [about_Using][16] -[01]: about_Classes_Properties.md -[02]: about_Classes_Methods.md -[03]: about_Classes_Constructors.md -[04]: about_Hidden.md -[05]: about_Classes_Properties.md#hidden-properties -[06]: about_Classes_Methods.md#hidden-methods -[07]: about_Classes_Constructors.md#hidden-constructors -[08]: about_Classes_Properties.md#static-properties -[09]: about_Classes_Methods.md#static-methods -[10]: about_Classes_Constructors.md#static-constructors -[11]: about_Classes_Inheritance.md -[12]: about_Using.md -[13]: /dotnet/api/system.management.automation.psreference -[14]: about_Enum.md -[15]: about_language_keywords.md -[16]: about_methods.md +[01]: #example-5---class-definition-with-and-without-runspace-affinity +[02]: about_Classes_Constructors.md +[03]: about_Classes_Constructors.md#hidden-constructors +[04]: about_Classes_Constructors.md#static-constructors +[05]: about_Classes_Inheritance.md +[06]: about_Classes_Methods.md +[07]: about_Classes_Methods.md#hidden-methods +[08]: about_Classes_Methods.md#static-methods +[09]: about_Classes_Properties.md +[10]: about_Classes_Properties.md#hidden-properties +[11]: about_Classes_Properties.md#static-properties +[12]: about_Enum.md +[13]: about_Hidden.md +[14]: about_language_keywords.md +[15]: about_methods.md +[16]: about_Using.md +[17]: xref:System.Management.Automation.PSReference diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md index 619464f28a74..0808161e37d1 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md @@ -251,10 +251,10 @@ which was published 86 years ago. ### Example 4 - Class with static members -The **BookList** class in this example builds on the **Book** class in example -2. While the **BookList** class can't be marked static itself, the -implementation only defines the **Books** static property and a set of static -methods for managing that property. +The **BookList** class in this example builds on the **Book** class in the +previous example. While the **BookList** class can't be marked static itself, +the implementation only defines the **Books** static property and a set of +static methods for managing that property. ```powershell class BookList { @@ -485,7 +485,7 @@ Properties are variables declared in the class scope. A property can be of any built-in type or an instance of another class. Classes can have zero or more properties. Classes don't have a maximum property count. -For more information, see [about_Classes_Properties][01]. +For more information, see [about_Classes_Properties][09]. ## Class methods @@ -495,7 +495,7 @@ method doesn't return any output, it must have the **Void** output type. If a method doesn't explicitly define an output type, the method's output type is **Void**. -For more information, see [about_Classes_Methods][02]. +For more information, see [about_Classes_Methods][06]. ## Class constructors @@ -504,7 +504,7 @@ moment of creating the instance of the class. Constructors have the same name as the class. Constructors might have parameters, to initialize the data members of the new object. -For more information, see [about_Classes_Constructors][03]. +For more information, see [about_Classes_Constructors][02]. ## Hidden keyword @@ -533,11 +533,11 @@ Hidden class members are: > When you hide any constructor, the `new()` option is removed from > IntelliSense and completion results. -For more information about the keyword, see [about_Hidden][04]. For more -information about hidden properties, see [about_Classes_Properties][05]. For -more information about hidden methods, see [about_Classes_Methods][06]. For +For more information about the keyword, see [about_Hidden][13]. For more +information about hidden properties, see [about_Classes_Properties][10]. For +more information about hidden methods, see [about_Classes_Methods][07]. For more information about hidden constructors, see -[about_Classes_Constructors][07]. +[about_Classes_Constructors][03]. ## Static keyword @@ -551,9 +551,9 @@ available always. All static properties live for the entire session span. The `static` keyword only applies to class members, not a class itself. For more information about static properties, see -[about_Classes_Properties][08]. For more information about static methods, see -[about_Classes_Methods][09]. For more information about static constructors, -see [about_Classes_Constructors][10]. +[about_Classes_Properties][11]. For more information about static methods, see +[about_Classes_Methods][08]. For more information about static constructors, +see [about_Classes_Constructors][04]. ## Inheritance in PowerShell classes @@ -569,8 +569,7 @@ inherits from an interface must implement that contract. When it does, the class can be used like any other class implementing that interface. For more information about deriving classes that inherit from a base class or -implement interfaces, see -[about_Classes_Inheritance][11]. +implement interfaces, see [about_Classes_Inheritance][05]. ## NoRunspaceAffinity attribute @@ -592,8 +591,7 @@ thread and the thread's current session state. The attribute was added in PowerShell 7.4. For an illustration of the difference in behavior for classes with and without -the `NoRunspaceAffinity` attribute, see -[Example 4](#example-4---class-definition-with-and-without-runspace-affinity). +the `NoRunspaceAffinity` attribute, see [Example 5][01]. ## Export classes with type accelerators @@ -679,7 +677,7 @@ consistently import classes defined in nested modules or classes defined in scripts that are dot-sourced into the root module. Define classes that you want to be available to users outside of the module directly in the root module. -For more information about the `using` statement, see [about_Using][12]. +For more information about the `using` statement, see [about_Using][16]. ## Load newly changed code during development @@ -706,7 +704,7 @@ parameters can't be used with class members. The **PSReference** class was designed to support COM objects. COM objects have cases where you need to pass a value in by reference. -For more information, see [PSReference Class][13]. +For more information, see [PSReference Class][17]. ## Limitations @@ -826,30 +824,31 @@ workaround for those limitations, if any. ## See also -- [about_Classes_Constructors][03] -- [about_Classes_Inheritance][11] -- [about_Classes_Methods][02] -- [about_Classes_Properties][01] -- [about_Enum][14] -- [about_Hidden][04] -- [about_Language_Keywords][15] -- [about_Methods][16] -- [about_Using][12] +- [about_Classes_Constructors][02] +- [about_Classes_Inheritance][05] +- [about_Classes_Methods][06] +- [about_Classes_Properties][09] +- [about_Enum][12] +- [about_Hidden][13] +- [about_Language_Keywords][14] +- [about_Methods][15] +- [about_Using][16] -[01]: about_Classes_Properties.md -[02]: about_Classes_Methods.md -[03]: about_Classes_Constructors.md -[04]: about_Hidden.md -[05]: about_Classes_Properties.md#hidden-properties -[06]: about_Classes_Methods.md#hidden-methods -[07]: about_Classes_Constructors.md#hidden-constructors -[08]: about_Classes_Properties.md#static-properties -[09]: about_Classes_Methods.md#static-methods -[10]: about_Classes_Constructors.md#static-constructors -[11]: about_Classes_Inheritance.md -[12]: about_Using.md -[13]: /dotnet/api/system.management.automation.psreference -[14]: about_Enum.md -[15]: about_language_keywords.md -[16]: about_methods.md +[01]: #example-5---class-definition-with-and-without-runspace-affinity +[02]: about_Classes_Constructors.md +[03]: about_Classes_Constructors.md#hidden-constructors +[04]: about_Classes_Constructors.md#static-constructors +[05]: about_Classes_Inheritance.md +[06]: about_Classes_Methods.md +[07]: about_Classes_Methods.md#hidden-methods +[08]: about_Classes_Methods.md#static-methods +[09]: about_Classes_Properties.md +[10]: about_Classes_Properties.md#hidden-properties +[11]: about_Classes_Properties.md#static-properties +[12]: about_Enum.md +[13]: about_Hidden.md +[14]: about_language_keywords.md +[15]: about_methods.md +[16]: about_Using.md +[17]: xref:System.Management.Automation.PSReference diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md index 0478cf4476d3..1f675bbbfcfc 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md @@ -251,10 +251,10 @@ which was published 86 years ago. ### Example 4 - Class with static members -The **BookList** class in this example builds on the **Book** class in example -2. While the **BookList** class can't be marked static itself, the -implementation only defines the **Books** static property and a set of static -methods for managing that property. +The **BookList** class in this example builds on the **Book** class in the +previous example. While the **BookList** class can't be marked static itself, +the implementation only defines the **Books** static property and a set of +static methods for managing that property. ```powershell class BookList { @@ -485,7 +485,7 @@ Properties are variables declared in the class scope. A property can be of any built-in type or an instance of another class. Classes can have zero or more properties. Classes don't have a maximum property count. -For more information, see [about_Classes_Properties][01]. +For more information, see [about_Classes_Properties][09]. ## Class methods @@ -495,7 +495,7 @@ method doesn't return any output, it must have the **Void** output type. If a method doesn't explicitly define an output type, the method's output type is **Void**. -For more information, see [about_Classes_Methods][02]. +For more information, see [about_Classes_Methods][06]. ## Class constructors @@ -504,7 +504,7 @@ moment of creating the instance of the class. Constructors have the same name as the class. Constructors might have parameters, to initialize the data members of the new object. -For more information, see [about_Classes_Constructors][03]. +For more information, see [about_Classes_Constructors][02]. ## Hidden keyword @@ -533,11 +533,11 @@ Hidden class members are: > When you hide any constructor, the `new()` option is removed from > IntelliSense and completion results. -For more information about the keyword, see [about_Hidden][04]. For more -information about hidden properties, see [about_Classes_Properties][05]. For -more information about hidden methods, see [about_Classes_Methods][06]. For +For more information about the keyword, see [about_Hidden][13]. For more +information about hidden properties, see [about_Classes_Properties][10]. For +more information about hidden methods, see [about_Classes_Methods][07]. For more information about hidden constructors, see -[about_Classes_Constructors][07]. +[about_Classes_Constructors][03]. ## Static keyword @@ -551,9 +551,9 @@ available always. All static properties live for the entire session span. The `static` keyword only applies to class members, not a class itself. For more information about static properties, see -[about_Classes_Properties][08]. For more information about static methods, see -[about_Classes_Methods][09]. For more information about static constructors, -see [about_Classes_Constructors][10]. +[about_Classes_Properties][11]. For more information about static methods, see +[about_Classes_Methods][08]. For more information about static constructors, +see [about_Classes_Constructors][04]. ## Inheritance in PowerShell classes @@ -569,8 +569,7 @@ inherits from an interface must implement that contract. When it does, the class can be used like any other class implementing that interface. For more information about deriving classes that inherit from a base class or -implement interfaces, see -[about_Classes_Inheritance][11]. +implement interfaces, see [about_Classes_Inheritance][05]. ## NoRunspaceAffinity attribute @@ -592,8 +591,7 @@ thread and the thread's current session state. The attribute was added in PowerShell 7.4. For an illustration of the difference in behavior for classes with and without -the `NoRunspaceAffinity` attribute, see -[Example 4](#example-4---class-definition-with-and-without-runspace-affinity). +the `NoRunspaceAffinity` attribute, see [Example 5][01]. ## Export classes with type accelerators @@ -679,7 +677,7 @@ consistently import classes defined in nested modules or classes defined in scripts that are dot-sourced into the root module. Define classes that you want to be available to users outside of the module directly in the root module. -For more information about the `using` statement, see [about_Using][12]. +For more information about the `using` statement, see [about_Using][16]. ## Load newly changed code during development @@ -706,7 +704,7 @@ parameters can't be used with class members. The **PSReference** class was designed to support COM objects. COM objects have cases where you need to pass a value in by reference. -For more information, see [PSReference Class][13]. +For more information, see [PSReference Class][17]. ## Limitations @@ -826,30 +824,31 @@ workaround for those limitations, if any. ## See also -- [about_Classes_Constructors][03] -- [about_Classes_Inheritance][11] -- [about_Classes_Methods][02] -- [about_Classes_Properties][01] -- [about_Enum][14] -- [about_Hidden][04] -- [about_Language_Keywords][15] -- [about_Methods][16] -- [about_Using][12] +- [about_Classes_Constructors][02] +- [about_Classes_Inheritance][05] +- [about_Classes_Methods][06] +- [about_Classes_Properties][09] +- [about_Enum][12] +- [about_Hidden][13] +- [about_Language_Keywords][14] +- [about_Methods][15] +- [about_Using][16] -[01]: about_Classes_Properties.md -[02]: about_Classes_Methods.md -[03]: about_Classes_Constructors.md -[04]: about_Hidden.md -[05]: about_Classes_Properties.md#hidden-properties -[06]: about_Classes_Methods.md#hidden-methods -[07]: about_Classes_Constructors.md#hidden-constructors -[08]: about_Classes_Properties.md#static-properties -[09]: about_Classes_Methods.md#static-methods -[10]: about_Classes_Constructors.md#static-constructors -[11]: about_Classes_Inheritance.md -[12]: about_Using.md -[13]: /dotnet/api/system.management.automation.psreference -[14]: about_Enum.md -[15]: about_language_keywords.md -[16]: about_methods.md +[01]: #example-5---class-definition-with-and-without-runspace-affinity +[02]: about_Classes_Constructors.md +[03]: about_Classes_Constructors.md#hidden-constructors +[04]: about_Classes_Constructors.md#static-constructors +[05]: about_Classes_Inheritance.md +[06]: about_Classes_Methods.md +[07]: about_Classes_Methods.md#hidden-methods +[08]: about_Classes_Methods.md#static-methods +[09]: about_Classes_Properties.md +[10]: about_Classes_Properties.md#hidden-properties +[11]: about_Classes_Properties.md#static-properties +[12]: about_Enum.md +[13]: about_Hidden.md +[14]: about_language_keywords.md +[15]: about_methods.md +[16]: about_Using.md +[17]: xref:System.Management.Automation.PSReference From c003d9bfa8ee07062b083d389b341a13b776c48a Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Thu, 22 Jan 2026 10:53:41 -0600 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md | 2 +- reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md | 2 +- reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md | 2 +- reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md index 4e6b0f1af288..420ea9aa2911 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,7 +117,7 @@ class Book { ``` The following example shows how the default constructor can assign the values -of a compatible using type coercion. In this example, a hashtable is used to +from a compatible value using type coercion. In this example, a hashtable is used to provide the property values. ```powershell diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md index fe21c7f26690..64332e836f3d 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,7 +117,7 @@ class Book { ``` The following example shows how the default constructor can assign the values -of a compatible using type coercion. In this example, a hashtable is used to +of a compatible value using type coercion. In this example, a hashtable is used to provide the property values. ```powershell diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md index 0808161e37d1..cf57af782e2a 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,7 +117,7 @@ class Book { ``` The following example shows how the default constructor can assign the values -of a compatible using type coercion. In this example, a hashtable is used to +from a compatible value using type coercion. In this example, a hashtable is used to provide the property values. ```powershell diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md index 1f675bbbfcfc..00140ed4512f 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,7 +117,7 @@ class Book { ``` The following example shows how the default constructor can assign the values -of a compatible using type coercion. In this example, a hashtable is used to +from a compatible hashtable using type coercion. In this example, a hashtable is used to provide the property values. ```powershell From 6427a22e3df41d9365be2cc9634a5da8800e9bb5 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Thu, 22 Jan 2026 10:55:12 -0600 Subject: [PATCH 4/4] Reflow --- .../5.1/Microsoft.PowerShell.Core/About/about_Classes.md | 4 ++-- .../7.4/Microsoft.PowerShell.Core/About/about_Classes.md | 4 ++-- .../7.5/Microsoft.PowerShell.Core/About/about_Classes.md | 4 ++-- .../7.6/Microsoft.PowerShell.Core/About/about_Classes.md | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md index 420ea9aa2911..f05531a2ccb2 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,8 +117,8 @@ class Book { ``` The following example shows how the default constructor can assign the values -from a compatible value using type coercion. In this example, a hashtable is used to -provide the property values. +from a compatible value using type coercion. In this example, a hashtable is +used to provide the property values. ```powershell $Book1 = [Book] @{ diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md index 64332e836f3d..95ca108efd9f 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,8 +117,8 @@ class Book { ``` The following example shows how the default constructor can assign the values -of a compatible value using type coercion. In this example, a hashtable is used to -provide the property values. +from a compatible value using type coercion. In this example, a hashtable is +used to provide the property values. ```powershell $Book1 = [Book] @{ diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md index cf57af782e2a..268104a63bb5 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,8 +117,8 @@ class Book { ``` The following example shows how the default constructor can assign the values -from a compatible value using type coercion. In this example, a hashtable is used to -provide the property values. +from a compatible value using type coercion. In this example, a hashtable is +used to provide the property values. ```powershell $Book1 = [Book] @{ diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md index 00140ed4512f..77f92f29e3be 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Classes.md @@ -117,8 +117,8 @@ class Book { ``` The following example shows how the default constructor can assign the values -from a compatible hashtable using type coercion. In this example, a hashtable is used to -provide the property values. +from a compatible value using type coercion. In this example, a hashtable is +used to provide the property values. ```powershell $Book1 = [Book] @{