Invariable order of $PSVersionTable#3530
Invariable order of $PSVersionTable#3530daxian-dbw merged 2 commits intoPowerShell:masterPowerShell/PowerShell:masterfrom iSazonov:psversiontableformatiSazonov/PowerShell:psversiontableformatCopy head branch name to clipboard
Conversation
Provides output $PSVersionTable properties in alphabetical order.
| using System.Reflection; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; |
There was a problem hiding this comment.
I've been playing with different options.
Removed.
|
Please add a test |
|
@SteveL-MSFT I added tests. |
| /// <summary> | ||
| /// Represents an implementation of '$PSVersionTable' variable. | ||
| /// The implementation contains ordered 'Keys' and 'GetEnumerator' to get user-friendly output. | ||
| /// </summary> |
There was a problem hiding this comment.
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.
VS Code detects this as error and build failed too without explicity adding IEnumerable.
| get | ||
| { | ||
| Array arr = new string[base.Keys.Count]; | ||
| base.Keys.CopyTo(arr, 0); |
There was a problem hiding this comment.
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.
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.
Maybe an OrderedDictionary should be used here.
There was a problem hiding this comment.
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.
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.
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.