-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Summary of the new feature/enhancement
v7.0 added support to Select-Object
for treating the entries of [hashtable]
input objects like properties that can be selected; e.g.:
# v7+ only:
# In v6-, this would only work with a [pscustomobject] "cast".
PS> @{ one = 1; two = 2; three = 3 } | Select-Object three, one
three one
----- ---
3 1
This interchangeable use of hashtables and (custom) objects is useful, and also implemented in other cmdlets, such as ConvertTo-Json
.
As a user, I'd like to see the same support implemented for other dictionary-like types as well, notably ordered hashtables and generic dictionaries:
# WISHFUL THINKING - does NOT currently work as expected (the named entries' values aren't extracted).
PS> [ordered] @{ one = 1; two = 2; three = 3 } | Select-Object three, one
three one
----- ---
3 1
# WISHFUL THINKING - does NOT currently work as expected (the named entries' values aren't extracted).
PS> $gd = [System.Collections.Generic.Dictionary[string, object]]::new(); $gd.Add('one', 1); $gd.Add('two', 2); $gd.Add('three', 3); $gd | Select-Object three, one
three one
----- ---
3 1
Backward compatibility considerations:
While technically a breaking change - currently only the dictionary's own properties rather than its entries are selected from - it is the same change that has already been deemed acceptable for [hashtable]
instances.
The dictionary's own properties will still be selectable, but will be shadowed by entries with keys of the same name.
Proposed implementation details
Support treating the entries of any input type that implements IDictionary
as properties.