Skip to main content

requiredenum by Yaroslav

NuGet / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Name: requiredenum

RequiredEnum is an open-source analyzer that helps handle all enum values for switch.

Author: Yaroslav

NuGet: https://www.nuget.org/packages/requiredenum/

You can find more details at https://github.com/emptycoder/RequiredEnum

Source: https://github.com/emptycoder/RequiredEnum

Author​

note

Yaroslav Alt text

Original Readme​

note

RequiredEnum

RequiredEnum is an open-source analyzer that helps handle all enum values for switch.

Installation

NuGet: dotnet add package requiredenum

Usage

Just add 'Required' prefix for any name of enum in your project and you will get the error when one of cases weren't handle in a switch statement.

var test = (RequiredNumbers) Random.Shared.Next(0, Enum.GetNames(typeof(RequiredNumbers)).Length);
switch (test)
{
case RequiredNumbers.Zero:
break;
case RequiredNumbers.One:
break;
default:
throw new ArgumentOutOfRangeException();
}

internal enum RequiredNumbers
{
Zero,
One,
Two
}

This code will throw the error ('Two' case wasn't handle) and it can't be compiled.

License

RequiredEnum distributed under MIT license.

About​

note

Raise an error at compile time if not have switch handle case all enums values

How to use​

Example (source csproj, source files)​

This is the CSharp Project that references requiredenum

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RequiredEnum" Version="0.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>


</Project>

Generated Files​

Useful​

Download Example (.NET C#)​

Share requiredenum​

https://ignatandrei.github.io/RSCG_Examples/v2/docs/requiredenum

Category "Enum" has the following generators:​

1 Aigamo.MatchGenerator Nuget GitHub Repo stars 2026-04-08

2 CredFetoEnum Nuget GitHub Repo stars 2023-10-12

3 EnumClass Nuget GitHub Repo stars 2023-08-08

4 EnumsEnhanced Nuget GitHub Repo stars 2025-08-05

5 EnumUtilities Nuget GitHub Repo stars 2024-04-05

6 Flaggen Nuget GitHub Repo stars 2025-07-23

7 FusionReactor Nuget GitHub Repo stars 2024-04-06

8 Genbox.FastEnum Nuget GitHub Repo stars 2025-08-03

9 jos.enumeration Nuget GitHub Repo stars 2025-07-20

10 LayeredCraft.OptimizedEnums Nuget GitHub Repo stars 2026-09-06

11 LinkDotNet.Enumeration Nuget GitHub Repo stars 2026-05-14

12 NetEscapades.EnumGenerators Nuget GitHub Repo stars 2023-04-16

13 PMart.Enumeration NugetNuget GitHub Repo stars 2025-03-25

14 Porticle.Enumly Nuget GitHub Repo stars 2026-07-02

15 RapidEnum Nuget GitHub Repo stars 2025-10-04

16 requiredenum Nuget GitHub Repo stars 2025-08-14

17 TaggedEnum Nuget GitHub Repo stars 2026-04-05

See category​

Enum