https://github.com/ricardoboss/Flaggen
https://github.com/ricardoboss/Flaggen
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ricardoboss/Flaggen
- Owner: ricardoboss
- License: mit
- Created: 2025-04-05T14:55:46.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-06-07T13:29:34.000Z (9 months ago)
- Last Synced: 2025-08-16T12:38:11.367Z (7 months ago)
- Language: C#
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- RSCG_Examples - https://github.com/ricardoboss/Flaggen
README
# Flaggen
A C# source generator that generates extension methods for flags enums.
## Usage
Install the package:
```shell
dotnet add package Flaggen
```
Suppose we have this enum:
```csharp
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:
```csharp
// 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](LICENSE.md)