You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeWG-Languageparser, language semanticsWG-NeedsReviewNeeds a review by the labeled Working Group
I have the following few things that keep bugging me when I write classes and would would be great to seem them appear in a next version (or at least a few of them)
Remove the need to reload classes (Currently, when developing, one needs to kill the console, and reload the class to get the latest version. IT would make sense to have the same functionality as in functions: Just F5, and the old version of classes get overwritten by the new version, and we can use it immediatley).
Reacted by Mark Kraus, Rob Holt, David das Neves, Jeremy Herbison, James Anderson, ChendrayanV, Kevin Bates, SamPosh, Patrick Meinecke, Graham Beer and 13 more
Stéphane (@Stephanevg) thanks for opening this issue, I updated your description into checkboxes so we can track progress as the different items won't all be addressed at once.
Stéphane (@Stephanevg) What do you mean when you say "Creation of static and non static internal classes". (I can think of a couple of interpretations but i'd like to hear what you're thinking.)
The order of classes (with inheritance) should not matter when in a single file
As a module author, I concat all my classes and functions into the psm1 at publishing time.
The ability to create classes in a namespace or auto namespace based on module name.
Use of default values or optional parameters in constructors
A way to export classes from a module in a discoverable way
Add option to mark class as hidden so using module does not expose or import them. (private classes)
A Get-Class -Module type of command like Get-Command
The ability to create a class based cmdlet in PowerShell
I want to ask for true private classes and members, but I am aware of why that does not work in PowerShell.
Reacted by Matt McNabb, Stéphane, Joel Bennett, Thomas Nieto, Mikey Lombardi (He/Him) and rdnaskelz
In my module RegardsCitoyensPS, some of the constructors I have build are simply HUGE, implementing the Builder patter would allow me reduce this.
I want to create a static internal class called Builder to whom I would delegate the mechanism of the creation of the Object. In the end, I will simplify the process of creation of an instance of my class for the engineers using my class.
In the end, I hope to reduce the complexity for the consumers of this class, and make the usage of a long constructor more straightforward and easier. The example above would result in something like this:
Today, I managed to make it work using a static method that would call [Depute]::New() and methods in [Depute] to add the different properties and that return $this.
It works, but I actually liked the idea of having an internal class to attach functionality to it, and build my class through that Static class.
Steve Lee (@SteveL-MSFT) done. To me, everything that would help us to simply the implementation of Design patterns should be highest prio. (Interfaces and Abstract Classes are the two main ones for me).
Adding help, is really secondary in my opinion, BUT really necessary.
Also, There is another small pain I have with Classes, is how we have to load them.
As a lot of PowerShell users, for functions, I had a folder Private and Public, containing several .ps1 files. Each file, contained a function, which I dot sourced via the .psm1
This way of organizing an item per file is not possible using classes, since a Class must be the very first thing to be loaded. Which means, the very first line of a Script.
In the end, as Kevin Marquette (@KevinMarquette) mentionned, Either during Build all the Classes will be merged in one psm1 file, or they are all already in a single file during developement.
What I understood from the powershell team members present at psconf in Germany, is that this behaviour was really difficult to change.
I was hoping that that we could find a solution for this.
Maybe, a new property in a .psd1 file with a property like ClassFolderToLoad = @(.\Classes\Public\) which would automatically load the classes during each module load could be an idea?
But this is for me really a small small point. The main topics for me at the moment are Interface and Abstract classes.
Oui, My first language is French ;)
and oui, you are correct. I meant nested / inner class, when I referred to Internal class. (I updated the first post mentionning Nested Classes instead of internal)
If we add all the mentioned thing then is that not called C#?
We would like all the good class features that C# has, but allow us to do it in PowerShell. This is a valid request because calling out to PowerShell from C# is not near as easy as just writing PowerShell.
SamPosh (@SamPosh) Also, many of the features requested here are common polymorphic class features in many Object Oriented programming languages, not just C#. Classes in PowerShell open up a language-native Object Oriented programming paradigm. Unfortunately, the current implementation of classes in PowerShell offer little benefit over advanced features of PSCustomObjects which has hindered adoption. Addition of features requested in this issue improve Object Oriented paradigm and bring is closer to parity with other Object Oriented languages.
Reacted by Stéphane, Michael Klement, Rain Sallow (/u/ta11ow), Matt McNabb, Anthony Allen, Thomas Nieto and Mikey Lombardi (He/Him)
Reacted by Flavien MICHALECZEK, Rain Sallow (/u/ta11ow), Mikey Lombardi (He/Him) and blaisemGH
Hi, I was wondering if any preogress has been done on this one? Steve Lee (@SteveL-MSFT) It seems like this one is not assigned anymore. It would be great to have these features / fixes implemented for 6.2
Stéphane (@Stephanevg) unfortunately at this time, we can't commit to addressing this issue in 6.2 timeframe perhaps 1 or 2 items may make it, but the team is busy with other necessary work right now
We should be able to use readonly modifier for class properties in some way, to make them readonly. But, we can't use fields in classes... We can use getter and setter approach for this, but there's no way to make setter private/protected. So, basically, there's no way to make member readonly or writeable for internal use. Every PSClass is exposed by default.
There's no support for namespaces in PSClasses. There's no way to even basically mimic namespaces, like [ModuleName.ClassName]. PowerShell automatically assume what there's no way should exist two classes with same name, using scoping of classes instead.
I could mention the Generics, but these ones are extreme for PowerShell for now. So at least PowerShell should support using them from assemblies, allow using generic methods (#5146) or allow generic inheritance (I could think of inheriting from IDictionary<String,Object>).
I think it would be awesome to get something like C# 9 records. I primarily use classes over [PSCustomObject] just to get reasonable ToString() and Equals(). This requires bunch of boilerplate, some of it I can abstract away with a helper returning a tuple of all properties to forward Equals() and GetHashCode().
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
I don't believe we should close this issue. It was mentioned a few times that this would receive some more love in the next Coming versions, but It looks like investments have been made in other areas that had a higher priority.
Is there some buffer for this one now Steve Lee (@SteveL-MSFT) ? It has been open for a while, and it would be great to have at least some of the points crossed out one day.
now arbitrary C# class(maybe huge) needs to be compiled into dll libs(assemblies :)(not only on Windows :) and be called and some boilerplatebee(or not so ugly be) made, so nice command CLI programs could be made and also GUI when required.
but MSFT is not going the easy way: Make Nice C# program Easy to Setup without Much Infra Needs(think Python) and be easily called from pwsh scripts which could admins, users do some script publishing... or daily automation jobs... with maybe fixing some coverage issues... maybe on BI Lakes Excel fronts... or db access from markdown, maybe from MS Fabric R samples...
Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeWG-Languageparser, language semanticsWG-NeedsReviewNeeds a review by the labeled Working Group
Activity
SteveL-MSFT commentedon Mar 19, 2018
cc Rob Holt (@rjmholt) if he wants to take on some of these
Stéphane (@Stephanevg) thanks for opening this issue, I updated your description into checkboxes so we can track progress as the different items won't all be addressed at once.
BrucePay commentedon Mar 19, 2018
Stéphane (@Stephanevg) What do you mean when you say "Creation of static and non static internal classes". (I can think of a couple of interpretations but i'd like to hear what you're thinking.)
KevinMarquette commentedon Mar 20, 2018
Here are some nice to have features
As a module author, I concat all my classes and functions into the psm1 at publishing time.
Get-Class -Moduletype of command likeGet-CommandI want to ask for true private classes and members, but I am aware of why that does not work in PowerShell.
SteveL-MSFT commentedon Mar 20, 2018
Stéphane (@Stephanevg) Kevin Marquette (@KevinMarquette) it would be great if you can order your lists from highest priority to lowest priority
Stephanevg commentedon Mar 20, 2018
Bruce Payette (@BrucePay) The main need I have behind this one is to implement the Builder Pattern.
In my module RegardsCitoyensPS, some of the constructors I have build are simply HUGE, implementing the Builder patter would allow me reduce this.
I want to create a static internal class called Builder to whom I would delegate the mechanism of the creation of the Object. In the end, I will simplify the process of creation of an instance of my class for the engineers using my class.
Example
This is my use case:
Current -->
Ho I imagined implementing the Builder Pattern to solve this:
Usage
In the end, I hope to reduce the complexity for the consumers of this class, and make the usage of a long constructor more straightforward and easier. The example above would result in something like this:
That is how I imagined it.
Today, I managed to make it work using a static method that would call [Depute]::New() and methods in [Depute] to add the different properties and that return $this.
It works, but I actually liked the idea of having an internal class to attach functionality to it, and build my class through that Static class.
Is that what you had in mind Bruce Payette (@BrucePay) ?
Stephanevg commentedon Mar 20, 2018
Steve Lee (@SteveL-MSFT) done. To me, everything that would help us to simply the implementation of Design patterns should be highest prio. (Interfaces and Abstract Classes are the two main ones for me).
Adding help, is really secondary in my opinion, BUT really necessary.
rjmholt commentedon Mar 20, 2018
Stéphane (@Stephanevg) By internal here you mean a nested or inner class rather than an internal namepsace functionality? (I infer your primary language is French, just want to make sure I have the right idea)
Stephanevg commentedon Mar 20, 2018
Also, There is another small pain I have with Classes, is how we have to load them.
As a lot of PowerShell users, for functions, I had a folder Private and Public, containing several .ps1 files. Each file, contained a function, which I dot sourced via the .psm1
This way of organizing an item per file is not possible using classes, since a Class must be the very first thing to be loaded. Which means, the very first line of a Script.
In the end, as Kevin Marquette (@KevinMarquette) mentionned, Either during Build all the Classes will be merged in one psm1 file, or they are all already in a single file during developement.
What I understood from the powershell team members present at psconf in Germany, is that this behaviour was really difficult to change.
I was hoping that that we could find a solution for this.
Maybe, a new property in a .psd1 file with a property like
ClassFolderToLoad = @(.\Classes\Public\)which would automatically load the classes during each module load could be an idea?But this is for me really a small small point. The main topics for me at the moment are Interface and Abstract classes.
Stephanevg commentedon Mar 20, 2018
Hi Rob Holt (@rjmholt)
Oui, My first language is French ;)
and oui, you are correct. I meant nested / inner class, when I referred to Internal class. (I updated the first post mentionning Nested Classes instead of internal)
KevinMarquette commentedon Mar 21, 2018
I updated the order on my list.
SamPosh commentedon Mar 21, 2018
If all the mentioned things are added then is that not called C#?
KevinMarquette commentedon Mar 21, 2018
We would like all the good class features that C# has, but allow us to do it in PowerShell. This is a valid request because calling out to PowerShell from C# is not near as easy as just writing PowerShell.
markekraus commentedon Mar 21, 2018
SamPosh (@SamPosh) Also, many of the features requested here are common polymorphic class features in many Object Oriented programming languages, not just C#. Classes in PowerShell open up a language-native Object Oriented programming paradigm. Unfortunately, the current implementation of classes in PowerShell offer little benefit over advanced features of
PSCustomObjects which has hindered adoption. Addition of features requested in this issue improve Object Oriented paradigm and bring is closer to parity with other Object Oriented languages.8 remaining items
Stephanevg commentedon Oct 18, 2018
Hi, I was wondering if any preogress has been done on this one? Steve Lee (@SteveL-MSFT) It seems like this one is not assigned anymore. It would be great to have these features / fixes implemented for 6.2
SteveL-MSFT commentedon Oct 19, 2018
Stéphane (@Stephanevg) unfortunately at this time, we can't commit to addressing this issue in 6.2 timeframe perhaps 1 or 2 items may make it, but the team is busy with other necessary work right now
Jaykul commentedon Oct 1, 2019
Or in the 7.x timeframe.
fixinggunsinair commentedon Apr 21, 2020
There should be a way to reference $this class static members in class methods and property default values.
Example of how it works now (at least in Windows PowerShell):
There's no
$this::Foothing.We should be able to use readonly modifier for class properties in some way, to make them readonly. But, we can't use fields in classes... We can use getter and setter approach for this, but there's no way to make setter private/protected. So, basically, there's no way to make member readonly or writeable for internal use. Every PSClass is exposed by default.
There's no support for namespaces in PSClasses. There's no way to even basically mimic namespaces, like
[ModuleName.ClassName]. PowerShell automatically assume what there's no way should exist two classes with same name, using scoping of classes instead.I could mention the Generics, but these ones are extreme for PowerShell for now. So at least PowerShell should support using them from assemblies, allow using generic methods (#5146) or allow generic inheritance (I could think of inheriting from
IDictionary<String,Object>).dkaszews commentedon Jul 18, 2023
I think it would be awesome to get something like C# 9 records. I primarily use classes over
[PSCustomObject]just to get reasonableToString()andEquals(). This requires bunch of boilerplate, some of it I can abstract away with a helper returning a tuple of all properties to forwardEquals()andGetHashCode().Shayan-To commentedon Jan 15, 2024
Is there any progress, or any other issue tracking the last check box (Remove the need to reload classes)?
Stephanevg commentedon Jan 15, 2024
I do not believe we should close this issue.
I don't believe we should close this issue. It was mentioned a few times that this would receive some more love in the next Coming versions, but It looks like investments have been made in other areas that had a higher priority.
Is there some buffer for this one now Steve Lee (@SteveL-MSFT) ? It has been open for a while, and it would be great to have at least some of the points crossed out one day.
hifron commentedon Nov 3, 2024
Modules pwsh lang docs with Script modules: howto
about Using docs
pwsh GUI
now arbitrary C# class(maybe huge) needs to be compiled into dll libs(assemblies :)(not only on Windows :) and be called and some boilerplate bee(or not so ugly be) made, so nice command CLI programs could be made and also GUI when required.
but MSFT is not going the easy way: Make Nice C# program Easy to Setup without Much Infra Needs(think Python) and be easily called from pwsh scripts which could admins, users do some script publishing... or daily automation jobs... with maybe fixing some coverage issues... maybe on BI Lakes Excel fronts... or db access from markdown, maybe from MS Fabric R samples...