8000 Make Select-Object treat any IDictionary type's entries as properties, as it already does for a [hasthable]s · Issue #13727 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
Make Select-Object treat any IDictionary type's entries as properties, as it already does for a [hasthable]s #13727
@mklement0

Description

@mklement0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0