ExhaustiveDictionary.Analyzer 1.0.1

dotnet add package ExhaustiveDictionary.Analyzer --version 1.0.1
                    
NuGet\Install-Package ExhaustiveDictionary.Analyzer -Version 1.0.1
                    
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="ExhaustiveDictionary.Analyzer" Version="1.0.1">
  <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="ExhaustiveDictionary.Analyzer" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ExhaustiveDictionary.Analyzer">
  <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 ExhaustiveDictionary.Analyzer --version 1.0.1
                    
#r "nuget: ExhaustiveDictionary.Analyzer, 1.0.1"
                    
#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 ExhaustiveDictionary.Analyzer@1.0.1
                    
#: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=ExhaustiveDictionary.Analyzer&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ExhaustiveDictionary.Analyzer&version=1.0.1
                    
Install as a Cake Tool

Exhaustive Dictionary Analyzer

Install the ExhaustiveDictionary.Attribute nuget package to get access to the [Exhaustive] attribute.

Rules:

EXHAUSTIVEDICT0001

Ensures all enum values are defined in dictionaries with an enum type as the key, when attributed with the [Exhaustive] attribute

enum Color { Red, Green, Blue };

[Exhaustive]
Dictionary<Color, string> ColorToHex = new() {
    { Color.Red, "#FF0000" }
};

Here the rule will complain because we have forgotten to add a value for Color.Green and Color.Blue to the dictionary

EXHAUSTIVEDICT0002

Ensure only one value per enum key is defined in the dictionary

enum Color { Red, Green, Blue };

[Exhaustive]
Dictionary<Color, string> ColorToHex = new() {
    { Color.Red, "#FF0000" },
    { Color.Green, "#008000" },
    { Color.Blue, "#0000FF" },
    { Color.Red, "#FF0000" },
};

Here the rule will complain because we have added Color.Red twice

EXHAUSTIVEDICT0003

Attribute was placed on invalid object, it can only be used on a Dictionary where the key is an Enum.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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.0.1 122 6/6/2025
1.0.0 104 6/6/2025