Powershell: When displaying method overloads, show optional parameters as such

Created on 1 Oct 2020  路  3Comments  路  Source: PowerShell/PowerShell

Summary of the new feature/enhancement

As a user, when I inspect the overloads of a given .NET method, I want to know which parameters are _optional_, so I only pass arguments to them if actually needed.

Accessing a method without invoking it (via (...)) conveniently shows all its overloads (signatures), but currently doesn't indicate which parameters are _optional_:

Add-Type -NameSpace demo -Name Foo -MemberDefinition 'public static void Bar(string param, int optParam = -1) { }'
# Show the method signature.
[demo.Foo]::Bar

_Current_ output - NO indication that optParam is optional):

-------------------
static void Bar(string param, int optParam)

_Desired_ output - clear indication that optParam is optional, ideally also with its default value, if technically feasible:

-------------------
static void Bar(string param, int optParam = -1)

Note: The same representation should be used for Get-Member output, as originally proposed in #7373.
I suspect that the implementation is shared anyway.

Issue-Enhancement Up-for-Grabs WG-Engine

Most helpful comment

I have code changes ready to submit to a PR that handles optional parameters. Could you please guide me on where I should add tests?

All 3 comments

Yeah it seems like optional parameters in public API's are becoming more and more popular (e.g. System.Reflection.Metadata, all the roslyn API's). I don't really know why that is, but some visibility would be 馃挴

I have code changes ready to submit to a PR that handles optional parameters. Could you please guide me on where I should add tests?

We haven't tests for the area. I suggest to create new file in test\powershell\engine\Api\ folder.

It would be great if you created tests for all related code paths.

Was this page helpful?
0 / 5 - 0 ratings