PowerShell / PowerShell/PowerShell

$PSBoundParametersDictionary should better inherit from System.Collections.Hashtable

Open
#21,263 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary of the new feature / enhancement

Currently the System.Management.Automation.PSBoundParametersDictionary class inherits from System.Collections.Generic.Dictionary<string, object>. This leads to following problems:

Whenever you add or remove elements to or from the automatic variable PSBoundParameters, a bool value is output. This is because the Add and Remove methods of the class Dictionary are not void.

That is for C# not a problem, but in Powershell, a script or function using those methods produces unwanted output.

I propose to inherit from the System.Collections.Hashtable class. This is actually also what a pwsh developer would expect.

I also recommend to define a specialized object for the Value object of each parameter element. This specialized object, let's call it PSBoundArgument should have two read-only properties:

IsBoundPositionally
IsBoundByDefaultValue

This approach is much more reasonable than the current solution of having a List of positional values as the BoundPositionally property of the dictionary!

That, of course, would complicate the assignment of new items to $PSBoundParameters, so the Add method has then to be overridden, so that objects of correct types are added to the hashtable. Maybe a third property called IsAdditional is then reqired too.

Proposed technical implementation details (optional)

No response

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.

Research direction

No file or test is named. Start by locating the System.Management.Automation.PSBoundParametersDictionary class and reviewing its current inheritance, Add/Remove behavior, and BoundPositionally representation; done would require settling and implementing the proposed API changes with suitable regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.