Skip to content

Commit cbf6359

Browse files
authored
Fix constructor calling order for derived classes (#12458)
1 parent 9ae0a03 commit cbf6359

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Classes_Constructors.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to define constructors for PowerShell classes.
33
Locale: en-US
4-
ms.date: 11/13/2023
4+
ms.date: 10/22/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes_constructors?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Classes_Constructors
@@ -393,8 +393,11 @@ For classes that don't inherit from another class, the ordering is:
393393

394394
For derived classes that inherit from another class, the ordering is:
395395

396-
1. The static constructor for the base class.
397-
1. The static constructor for the derived class.
396+
1. If the static constructor of the derived class doesn't depend on the base
397+
class, the static constructor of the derived class is called first.
398+
1. If the static constructor of the derived class depends on the base class,
399+
the static constructor of the base class is called before executing the line
400+
of code in the derived class that depends on base.
398401
1. If the derived class constructor explicitly calls a base constructor
399402
overload, it runs that constructor for the base class. If it doesn't
400403
explicitly call a base constructor, it runs the default constructor for the

reference/7.4/Microsoft.PowerShell.Core/About/about_Classes_Constructors.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to define constructors for PowerShell classes.
33
Locale: en-US
4-
ms.date: 10/13/2025
4+
ms.date: 10/22/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes_constructors?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Classes_Constructors
@@ -392,8 +392,11 @@ For classes that don't inherit from another class, the ordering is:
392392

393393
For derived classes that inherit from another class, the ordering is:
394394

395-
1. The static constructor for the base class.
396-
1. The static constructor for the derived class.
395+
1. If the static constructor of the derived class doesn't depend on the base
396+
class, the static constructor of the derived class is called first.
397+
1. If the static constructor of the derived class depends on the base class,
398+
the static constructor of the base class is called before executing the line
399+
of code in the derived class that depends on base.
397400
1. If the derived class constructor explicitly calls a base constructor
398401
overload, it runs that constructor for the base class. If it doesn't
399402
explicitly call a base constructor, it runs the default constructor for the

reference/7.5/Microsoft.PowerShell.Core/About/about_Classes_Constructors.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to define constructors for PowerShell classes.
33
Locale: en-US
4-
ms.date: 10/13/2025
4+
ms.date: 10/22/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes_constructors?view=powershell-7.5&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Classes_Constructors
@@ -392,8 +392,11 @@ For classes that don't inherit from another class, the ordering is:
392392

393393
For derived classes that inherit from another class, the ordering is:
394394

395-
1. The static constructor for the base class.
396-
1. The static constructor for the derived class.
395+
1. If the static constructor of the derived class doesn't depend on the base
396+
class, the static constructor of the derived class is called first.
397+
1. If the static constructor of the derived class depends on the base class,
398+
the static constructor of the base class is called before executing the line
399+
of code in the derived class that depends on base.
397400
1. If the derived class constructor explicitly calls a base constructor
398401
overload, it runs that constructor for the base class. If it doesn't
399402
explicitly call a base constructor, it runs the default constructor for the

reference/7.6/Microsoft.PowerShell.Core/About/about_Classes_Constructors.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to define constructors for PowerShell classes.
33
Locale: en-US
4-
ms.date: 10/13/2025
4+
ms.date: 10/22/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_classes_constructors?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Classes_Constructors
@@ -392,8 +392,11 @@ For classes that don't inherit from another class, the ordering is:
392392

393393
For derived classes that inherit from another class, the ordering is:
394394

395-
1. The static constructor for the base class.
396-
1. The static constructor for the derived class.
395+
1. If the static constructor of the derived class doesn't depend on the base
396+
class, the static constructor of the derived class is called first.
397+
1. If the static constructor of the derived class depends on the base class,
398+
the static constructor of the base class is called before executing the line
399+
of code in the derived class that depends on base.
397400
1. If the derived class constructor explicitly calls a base constructor
398401
overload, it runs that constructor for the base class. If it doesn't
399402
explicitly call a base constructor, it runs the default constructor for the

0 commit comments

Comments
 (0)