-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
As per .NET Platform compatibility rule DE0006 and PowerShell coding guidelines non-generic collections shouldn't be used.
In particular relevant for PowerShell would be System.Collections.ArrayList
and System.Collections.Hashtable
.
Most occurrences of ArrayList
are in C# code obviously, but some can be found in Pester test files too (due to the lack of an internal dynamic array type in PowerShell).
Those two styles are found in Pester tests:
New-Object System.Collections.ArrayList
[System.Collections.ArrayList]::new()
C# code
The replacement of the non-generic collections in C# code by the generic ones might be non-trivial due to the type problems. For new code and code changes the rule should be followed as the replacement is an on-going process.
Pester tests
For Pester test files the PowerShell syntax should be favored over the explicitly typed C# equivalents:
System.Collections.Hashtable
->@{}
System.Collections.ArrayList
->@()
(though being of typeArray
; in most cases the performance can be neglected using+=
operator on@()
on very small arrays; some instances might be refactored to use aForEach
loop which returns anArray
)