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 CredFetoEnum Nuget GitHub Repo stars 2023-10-12

2 EnumClass Nuget GitHub Repo stars 2023-08-08

3 EnumsEnhanced Nuget GitHub Repo stars 2025-08-05

4 EnumUtilities Nuget GitHub Repo stars 2024-04-05

5 Flaggen Nuget GitHub Repo stars 2025-07-23

6 FusionReactor Nuget GitHub Repo stars 2024-04-06

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

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

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

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

11 RapidEnum Nuget GitHub Repo stars 2025-10-04

12 requiredenum Nuget GitHub Repo stars 2025-08-14

See category

Enum