ExhaustiveDictionary.Analyzer
1.0.1
dotnet add package ExhaustiveDictionary.Analyzer --version 1.0.1
NuGet\Install-Package ExhaustiveDictionary.Analyzer -Version 1.0.1
<PackageReference Include="ExhaustiveDictionary.Analyzer" Version="1.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ExhaustiveDictionary.Analyzer" Version="1.0.1" />
<PackageReference Include="ExhaustiveDictionary.Analyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ExhaustiveDictionary.Analyzer --version 1.0.1
#r "nuget: ExhaustiveDictionary.Analyzer, 1.0.1"
#:package ExhaustiveDictionary.Analyzer@1.0.1
#addin nuget:?package=ExhaustiveDictionary.Analyzer&version=1.0.1
#tool nuget:?package=ExhaustiveDictionary.Analyzer&version=1.0.1
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.
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.