Beskar.Memory.Code.NoPrimitiveGenerator 10.0.1

dotnet add package Beskar.Memory.Code.NoPrimitiveGenerator --version 10.0.1
                    
NuGet\Install-Package Beskar.Memory.Code.NoPrimitiveGenerator -Version 10.0.1
                    
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="Beskar.Memory.Code.NoPrimitiveGenerator" Version="10.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Beskar.Memory.Code.NoPrimitiveGenerator" Version="10.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Beskar.Memory.Code.NoPrimitiveGenerator" />
                    
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 Beskar.Memory.Code.NoPrimitiveGenerator --version 10.0.1
                    
#r "nuget: Beskar.Memory.Code.NoPrimitiveGenerator, 10.0.1"
                    
#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 Beskar.Memory.Code.NoPrimitiveGenerator@10.0.1
                    
#: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=Beskar.Memory.Code.NoPrimitiveGenerator&version=10.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Beskar.Memory.Code.NoPrimitiveGenerator&version=10.0.1
                    
Install as a Cake Tool

Beskar.Memory.Code.NoPrimitiveGenerator

NuGet Version

Disclaimer: this is more of a joke generator ^^

A high-performance C# incremental source generator that generates enums covering the entire range of their underlying primitive types, along with zero-overhead math extension methods and operator overloads.


Features

  • Full Range Generation: Generates every valid value for underlying types (byte, sbyte, short, ushort).
  • Negative Value Handling: Formats negative values cleanly (e.g., ValueMinus128 = -128, ValueMinus1 = -1).
  • Extension Operator Overloads: Overloads standard operators (+, -, *, /, %, ++, --, and unary -/+ for signed types).
  • Extension Methods: Emits helper methods (Add, Subtract, Multiply, Divide, Modulo, Next, Previous, ToPrimitive, Negate, Abs).
  • Customizable: Configure the generated enum name, value prefix, and math extensions generation.

Quick Start & Byte Example

1. Declare Your Enum

Decorate an enum with [NoPrimitive] and optionally specify GeneratedName:

using Beskar.Memory.Code.NoPrimitiveGenerator.Attributes;

namespace MyProject;

[NoPrimitive(GeneratedName = "ByteEnum")]
public enum MyByte : byte
{
   None = 0
}

2. What Gets Generated

The generator produces ByteEnum and its accompanying math extensions and operator overloads:

// <auto-generated>
// This file is auto-generated by NoPrimitiveGenerator[1.0.0].
// </auto-generated>

#nullable enable

namespace MyProject;

public enum ByteEnum : byte
{
   Value0 = 0,
   Value1 = 1,
   Value2 = 2,
   // ...
   Value254 = 254,
   Value255 = 255,
}

public static partial class ByteEnumExtensions
{
   extension(ByteEnum value)
   {
      public byte ToPrimitive() => (byte)value;

      public ByteEnum Add(ByteEnum other) => (ByteEnum)((byte)value + (byte)other);
      public ByteEnum Add(byte other) => (ByteEnum)((byte)value + other);

      public ByteEnum Subtract(ByteEnum other) => (ByteEnum)((byte)value - (byte)other);
      public ByteEnum Subtract(byte other) => (ByteEnum)((byte)value - other);

      public ByteEnum Multiply(ByteEnum other) => (ByteEnum)((byte)value * (byte)other);
      public ByteEnum Multiply(byte other) => (ByteEnum)((byte)value * other);

      public ByteEnum Divide(ByteEnum other) => (ByteEnum)((byte)value / (byte)other);
      public ByteEnum Divide(byte other) => (ByteEnum)((byte)value / other);

      public ByteEnum Modulo(ByteEnum other) => (ByteEnum)((byte)value % (byte)other);
      public ByteEnum Modulo(byte other) => (ByteEnum)((byte)value % other);

      public ByteEnum Next() => (ByteEnum)((byte)value + 1);
      public ByteEnum Previous() => (ByteEnum)((byte)value - 1);

      public static ByteEnum operator +(ByteEnum left, ByteEnum right) => (ByteEnum)((byte)left + (byte)right);
      public static ByteEnum operator +(ByteEnum left, byte right) => (ByteEnum)((byte)left + right);
      public static ByteEnum operator +(byte left, ByteEnum right) => (ByteEnum)(left + (byte)right);

      public static ByteEnum operator -(ByteEnum left, ByteEnum right) => (ByteEnum)((byte)left - (byte)right);
      public static ByteEnum operator -(ByteEnum left, byte right) => (ByteEnum)((byte)left - right);
      public static ByteEnum operator -(byte left, ByteEnum right) => (ByteEnum)(left - (byte)right);

      public static ByteEnum operator *(ByteEnum left, ByteEnum right) => (ByteEnum)((byte)left * (byte)right);
      public static ByteEnum operator *(ByteEnum left, byte right) => (ByteEnum)((byte)left * right);
      public static ByteEnum operator *(byte left, ByteEnum right) => (ByteEnum)(left * (byte)right);

      public static ByteEnum operator /(ByteEnum left, ByteEnum right) => (ByteEnum)((byte)left / (byte)right);
      public static ByteEnum operator /(ByteEnum left, byte right) => (ByteEnum)((byte)left / right);
      public static ByteEnum operator /(byte left, ByteEnum right) => (ByteEnum)(left / (byte)right);

      public static ByteEnum operator %(ByteEnum left, ByteEnum right) => (ByteEnum)((byte)left % (byte)right);
      public static ByteEnum operator %(ByteEnum left, byte right) => (ByteEnum)((byte)left % right);
      public static ByteEnum operator %(byte left, ByteEnum right) => (ByteEnum)(left % (byte)right);

      public static ByteEnum operator ++(ByteEnum operand) => (ByteEnum)((byte)operand + 1);
      public static ByteEnum operator --(ByteEnum operand) => (ByteEnum)((byte)operand - 1);
   }
}

3. Math & Operator Usage Example

using MyProject;

var a = ByteEnum.Value10;
var b = ByteEnum.Value5;

// Using standard operators
var sum = a + b;             // ByteEnum.Value15
var diff = a - 2;            // ByteEnum.Value8
var product = a * b;         // ByteEnum.Value50
var division = a / b;        // ByteEnum.Value2
var mod = a % b;             // ByteEnum.Value0

sum++;                       // ByteEnum.Value16
diff--;                      // ByteEnum.Value7

// Using extension methods
var next = a.Next();         // ByteEnum.Value11
byte raw = sum.ToPrimitive();// 16

Attribute Options

Property Type Default Description
GeneratedName string? "{Name}Generated" Custom name for the generated enum.
ValuePrefix string? "Value" Prefix applied before positive and negative values.
GenerateMathExtensions bool true When true, emits math helper extension methods and operator overloads.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in 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
10.0.1 109 8/28/2026