8000 Invariable order of $PSVersionTable by iSazonov · Pull Request #3530 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 2 commits into from
Apr 13, 2017

Conversation

iSazonov
Copy link
Collaborator

Fix #3031.
Provides output $PSVersionTable properties in alphabetical order.

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;
Copy link
Member

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?

Copy link
Collaborator Author

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.

@SteveL-MSFT
Copy link
Member

Please add a test

@iSazonov
Copy link
Collaborator Author

@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
Copy link
Member

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?

8000 Copy link
Collaborator Author

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.

@daxian-dbw daxian-dbw merged commit acec58c into PowerShell:master Apr 13, 2017
@iSazonov iSazonov deleted the psversiontableformat branch April 13, 2017 06:22
{
Array arr = new string[base.Keys.Count];
base.Keys.CopyTo(arr, 0);
Array.Sort(arr, StringComparer.OrdinalIgnoreCase);
Copy link
Contributor

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

Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Collaborator Author
@iSazonov iSazonov Apr 14, 2017

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.

Copy link
Member

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

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0