Please provide ability to invoke generic methods with explicit type parameters.
Steps to demonstrate
or using a class:
class A {
static [string] GetTypeName[T]() { return [T].Name }
}
[A]::GetTypeName[string]()
(Array.Empty was chosen as a simplest possible example. In scripts Iʼd use @())
Current behavior
At line:1 char:16
+ [Array]::Empty[string]()
+ ~
Array index expression is missing or not valid.
At line:1 char:16
+ [Array]::Empty[string]()
+ ~~~~~~~
Unexpected token 'string]' in expression or statement.
At line:1 char:24
+ [Array]::Empty[string]()
+ ~
An expression was expected after '('.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArrayIndexExpression
Ruminations
I understand that itʼs not important to have full support of generics in a scripting language or to have 100% feature parity with C# (I might be wrong, — now we have classes in PowerShell after all 🤔)
Here are some not-very-elegant workarounds from the Interwebs:
Here are my questions:
- Is it possible to implement this at all? How hard it could be?
- Anyone tried to implement this before?
- Is it worthwhile?
Just posting this here for discussion. Didnʼt find any mentions of this problem in other issues.
Please provide ability to invoke generic methods with explicit type parameters.
Steps to demonstrate
or using a class:
(
Array.Emptywas chosen as a simplest possible example. In scripts Iʼd use@())Current behavior
Ruminations
I understand that itʼs not important to have full support of generics in a scripting language or to have 100% feature parity with C# (I might be wrong, — now we have
classesin PowerShell after all 🤔)Here are some not-very-elegant workarounds from the Interwebs:
Here are my questions:
Just posting this here for discussion. Didnʼt find any mentions of this problem in other issues.