PowerShell / PowerShell/PowerShell
Improve `OrderedHashtable` integration
@SeeminglyScience is already working on this.
Since Apr 3, 2023.
- 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-iscomparison:
$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
OrderedDictionaryclass
Currently the following returnsFalse, where I would like to see itTrueso that doesn't break scripts that test for anOrderedDictionarytype:
$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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.