question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DE0006: Non-generic collections shouldn't be used (especially in Pester tests)

See original GitHub issue

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 type Array; in most cases the performance can be neglected using += operator on @() on very small arrays; some instances might be refactored to use a ForEach loop which returns an Array)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TravisEz13commented, Aug 9, 2019

Individual rules are adjusted by configuration files in the repo. See the services web site for instructions, on how to add a configuration.

Codacy has been disable for C# because it is using an old version of C# for analysis

1reaction
KirkMunrocommented, Aug 9, 2019

Also to be clear, DE0006 recommends avoiding the use of non-generic collections in new code. For existing code we can consider the benefits gained from converting to generic collections where possible (i.e. for PowerShell, where such changes would be non-breaking), but that’s it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are non-generic collections in .NET obsolete?
It's true that you should avoid using non-generic collections unless you have a reason not not use a generic version. Thousands of lines...
Read more >
Data driven tests
Pester can generate tests based on data. This can range from providing multiple examples on a single It , to generating whole set...
Read more >
When to Use Generic Collections
Learn more about: When to use generic collections. ... Several generic collection types do not have nongeneric counterparts.
Read more >
(PDF) Childhood memories and musical constructions. ...
The aim of the paper is to explore the role played by references to childhood and youth in the composer's commentaries to his...
Read more >
Why You Should -Be Using Pester with Jonathan Moss
Pester is a test framework for PowerShell. It allows you to define all kinds of test cases and report the results. Using this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found