PowerShell / PowerShell/PowerShell

Improve `OrderedHashtable` integration

Đang mở
#19,157 4 bình luận 1 reaction 1 người được giao Xem trên GitHub

@SeeminglyScience đang làm issue này rồi.

Từ ngày 3/4/2023.

Issue-Enhancement Needs-Triage WG-Engine
Ngôn ngữ chính
C#
Star
55.5k
Fork
8.5k
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
88

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.