-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Invariable order of $PSVersionTable #3530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Provides output $PSVersionTable properties in alphabetical order.
@@ -5,6 +5,8 @@ | |||
using System.Diagnostics; | |||
using System.Reflection; | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using System.Linq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been playing with different options.
Removed.
Please add a test |
@SteveL-MSFT I added tests. |
/// Represents an implementation of '$PSVersionTable' variable. | ||
/// The implementation contains ordered 'Keys' and 'GetEnumerator' to get user-friendly output. | ||
/// </summary> | ||
public sealed class PSVersionHashTable : Hashtable, IEnumerable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class Hashtable : IDictionary, ICollection, IEnumerable, ...
Hashtable implements IEnumerable, so do you still need to specify IEnumerable
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VS Code detects this as error and build failed too without explicity adding IEnumerable
.
{ | ||
Array arr = new string[base.Keys.Count]; | ||
base.Keys.CopyTo(arr, 0); | ||
Array.Sort(arr, StringComparer.OrdinalIgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like this sorting - today PSVersion
shows up first, or at least it should.
With this change, it will be somewhat harder to see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree 100%. About the only thing I ever look for from this info is PSVersion
. This will make it harder to see that version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe an OrderedDictionary
should be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have several open discussions on adding additional rows. Alphabetical order will be even more useful after that.
If you want only PSVersion why don't use $PSVersionTable.PSVersion
?
I wonder how it makes Windows PowerShell for PSVersionHashTable
hashtable ?
I could slightly change this code to move PSVersion in the first place without moving to OrderedDictionary
Update: Moving to OrderedDictionary
may be not easy. I review the code - GetPSVersionTableForDownLevel
is used in serialization.cs and it is based on hashtable. So I didn't even imagine that there can be broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: Moving to OrderedDictionary may be not easy. I review the code - GetPSVersionTableForDownLevel is used in serialization.cs and it is based on hashtable. So I didn't even imagine that there can be broken.
This is a good point. Thanks @iSazonov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider putting PSVersion and PSEdition in the first and second positions. After that, I don't care much about the order. I suppose alphabetical after the first two would be fine.
Fix #3031.
Provides output $PSVersionTable properties in alphabetical order.