Flaggen 1.1.0

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

Flaggen

A C# source generator that generates extension methods for flags enums.

Usage

Install the package:

dotnet add package Flaggen

Suppose we have this enum:

using System;

[Flags]
public enum LovelyColors {
    RoseGold = 1 << 0,
    SeaGreen = 1 << 1,
    SunshineYellow = 1 << 2,
    BrightRed = 1 << 3,
}

The source generator will notice the [Flags] attribute and generate extension methods for this enum:

// initalize with some value
var myColors = LovelyColors.RoseGold | LovelyColors.SeaGreen;

// manipulate the flags
myColors.Add(LovelyColors.BrightRed);
myColors.Remove(LovelyColors.RoseGold);
myColors.Toggle(LovelyColors.SeaGreen);

// check for flags
if (myColors.Has(LovelyColors.SunshineYellow))
    Console.WriteLine("So shiny!");

All the extension methods using bitwise operators (so no reflection!), which makes them pretty fast (I will not prove this, but you get my trust-me-bro™️ guarantee).

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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.1.0 115 6/7/2025
1.0.1 93 4/5/2025
1.0.0 82 4/5/2025

# 1.1.0
- Made extension functions non-pure for a cleaner API
# 1.0.1
- Fix source link
# 1.0.0
- Initial release
- Generates extension methods for adding, removing, toggling and checking flags for enums