Skip to content

Add documentation for invoking generic methods with explicit type parameters #8533

@vexx32

Description

@vexx32

Prerequisites

  • Write a descriptive title.
  • Search the existing issues.

Summary of the new feature or changed behavior

Now that PowerShell/PowerShell#12412 was merged, we need to look at adding documentation around the syntax and some general use cases for calling generic methods where PowerShell can't infer the appropriate generic overload based on the argument types.

General syntax is:

# static generic methods
[type_name]::MethodName[generic_type_arguments](method_arguments)

# instance generic methods
$object.MethodName[generic_type_arguments](method_arguments)

# generic_type_arguments can be a a single type, or comma-separated list of types, like `[string, int]`, 
# including other generic types like `$obj.MethodName[string, System.Collections.Generic.Dictionary[string, int]]()`

I would expect some of the most common use cases for this would be in using heavily generic types like System.Collections.Concurrent.ConcurrentDictionary and static methods with generic arguments like those found in the System.Linq namespace.

Note that as illustrated in this comment that certain methods may still require type casting their arguments appropriately at the moment.

List of articles that need to be updated

Unsure which articles exactly at the moment.

Link to related PR in PowerShell/PowerShell repo

PowerShell/PowerShell#12412

Link to related Issues in PowerShell/PowerShell repo

PowerShell/PowerShell#5146

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions