CollectionExpressionKiller 1.3.0

dotnet add package CollectionExpressionKiller --version 1.3.0
                    
NuGet\Install-Package CollectionExpressionKiller -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CollectionExpressionKiller" Version="1.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CollectionExpressionKiller" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="CollectionExpressionKiller">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CollectionExpressionKiller --version 1.3.0
                    
#r "nuget: CollectionExpressionKiller, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CollectionExpressionKiller@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CollectionExpressionKiller&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=CollectionExpressionKiller&version=1.3.0
                    
Install as a Cake Tool

<div align="center">

Collection Expression Killer for C#

Ensures Explicit Coding Style for Code Review

nuget test   DeepWiki

</div>

 

Why?

Collection expression is useful for small scripts, demonstrations or other non-critical use cases but it is unclear what is actually created behind the scenes.

The source code should be explicitly expressing itself and eliminating "Something working" from the repository is important especially on code review on GitHub (no IDE assist).

Installation

dotnet add package CollectionExpressionKiller

.editorconfig Recommendation

Disable the suggestions relating to collection expressions.

dotnet_diagnostic.IDE0300.severity = silent   # Use collection expression for array
dotnet_diagnostic.IDE0301.severity = silent   # Use collection expression for empty
dotnet_diagnostic.IDE0305.severity = silent   # Use collection expression for fluent
dotnet_diagnostic.IDE0028.severity = silent   # Use collection initializers

 

Diagnostics Customization

Ability to disallow all expressions or complicated only.

  • CEK001: Disallow all collection expressions.
  • CEK002: Disallow expressions with 4 or more elements. (e.g., [1, 2, ..other, 4])
  • CEK003: Disallow expressions whose string representation is longer than 12 characters (including [ and ]).
  • CEK004: Disallow multiline expressions.
  • CEK005: Disallow collection expressions with elements. (i.e., Only [] is allowed)

Example usage:

values = [1234, 56789, .. values];  // Error: More than 12 chars

// To allow expression which is 3 or less elements in single line
#pragma warning disable CEK001
#pragma warning disable CEK003
#pragma warning disable CEK005

values = [1234, 56789, ..values];  // OK: Simple enough
values = [1234, 56789, ..values, ..other];  // Error: 4 elements

.editorconfig only allowing [] in entire project:

dotnet_diagnostic.CEK001.severity = none   # Collection expressions are disallowed
dotnet_diagnostic.CEK002.severity = none   # Collection expressions with more than 3 elements are disallowed
dotnet_diagnostic.CEK003.severity = none   # Long collection expression text is disallowed
dotnet_diagnostic.CEK004.severity = none   # Multiline collection expressions are disallowed
dotnet_diagnostic.CEK005.severity = error  # Collection expressions with elements are disallowed

How to Disable Analyzer

Disable for entire project by category with .editorconfig:

dotnet_analyzer_diagnostic.category-CollectionExprKiller.severity = none

Disable for entire project with .editorconfig:

dotnet_diagnostic.CEK001.severity = none
dotnet_diagnostic.CEK002.severity = none
dotnet_diagnostic.CEK003.severity = none
dotnet_diagnostic.CEK004.severity = none
dotnet_diagnostic.CEK005.severity = none

Disable for entire assembly:

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage(
    "CollectionExprKiller",
    "CEK001:Collection expressions are not allowed",
    Justification = "Approved for this assembly")]

[assembly: SuppressMessage(
    "CollectionExprKiller",
    "CEK002:Collection expressions must have fewer than 4 elements",
    Justification = "Approved for this assembly")]

[assembly: SuppressMessage(
    "CollectionExprKiller",
    "CEK003:Collection expression text length must be 12 or fewer characters",
    Justification = "Approved for this assembly")]

[assembly: SuppressMessage(
    "CollectionExprKiller",
    "CEK004:Collection expressions must be on a single line",
    Justification = "Approved for this assembly")]

[assembly: SuppressMessage(
    "CollectionExprKiller",
    "CEK005:Collection expressions must be empty",
    Justification = "Approved for this assembly")]

Disable for entire .cs file with #pragma:

#pragma warning disable CEK001
#pragma warning disable CEK002
#pragma warning disable CEK003
#pragma warning disable CEK004
#pragma warning disable CEK005

int[] values = [1, 2, 3, 4, ..otherCollection];
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 81 2/26/2026
1.2.0 92 2/13/2026
1.1.0 86 2/12/2026
1.0.0 96 2/11/2026