PowerShell / PowerShell/PowerShell

Improve `OrderedHashtable` integration

Open
#19,157 4 comments 1 reaction 1 assignee View on GitHub

@SeeminglyScience is already working on this.

Since Apr 3, 2023.

Issue-Enhancement Needs-Triage WG-Engine
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Summary of the new feature / enhancement

The new System.Management.Automation.OrderedHashtable class is a great step forward in moving to a dictionary that is ordered by default. Therefore I wouldn't be surprised that this System.Management.Automation.OrderedHashtable class would eventually replace the System.Collections.Specialized.OrderedDictionary class.

For this to happen, I would like to able to use the same syntactic sugars as with the Hashtable/Ordered type:

  • Preserve the hash literal node order
    Currently this doesn't work as expected (like it does for [PSCustomObject] and [Ordered]):
[System.Management.Automation.OrderedHashtable]@{ One = 1; Two = 2; Three = 3; Four = 4 }

Name                           Value
----                           -----
Two                            2
Four                           4
One                            1
Three                          3

Side note: unlike the OrderedDictionary class, I think it is ok that the OrderedDictionary is able to cast from an unordered (non-literal) hash table (assuming that it will be documented that the order is already decayed in this matter):

$Hashtable = @{ One = 1; Two = 2; Three = 3; Four = 4 }
[System.Management.Automation.OrderedHashtable]$HashTable
  • Ability to use the friendly name to cast
    As with the [Ordered] (and [HashTable]) type, I would like to be able to use it friendly name:
[OrderedHashtable]@{ One = 1; Two = 2; Three = 3; Four = 4 }
  • ability to compare with its friendly name
    As with the [Ordered] type (see: #10513), I would like to be able to use its friendly name for the -is comparison:
$OrderedHashtable = [System.Management.Automation.OrderedHashtable]@{ One = 1; Two = 2; Three = 3; Four = 4 }
$OrderedHashtable -is [OrderedHashtable]
  • Also, I would expect it somehow (pretend) to be derived from the OrderedDictionary class
    Currently the following returns False, where I would like to see it True so that doesn't break scripts that test for an OrderedDictionary type:
$OrderedHashtable = [System.Management.Automation.OrderedHashtable]@{ One = 1; Two = 2; Three = 3; Four = 4 }
$OrderedHashtable -is [Ordered]
False # Expected (wishful thinking) True

Related: #19073

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.