Skip to main content

VoloGen by Oleksandr Tsvirkun

NuGet / site data​

NugetNuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Name: VoloGen

Marker attribute for the VoloGen parsable source generator. Annotate a partial type with [AutoParsable] to generate IParsable<T>, ISpanParsable<T>, and optional IUtf8SpanParsable<T> implementations.

Author: Oleksandr Tsvirkun

NuGet: https://www.nuget.org/packages/VoloGen.Parsable/

https://www.nuget.org/packages/VoloGen.Parsable.Generator/

You can find more details at https://oleksandrtsvirkun.github.io/VoloGen/

Source: https://github.com/OleksandrTsvirkun/VoloGen

Author​

note

Oleksandr Tsvirkun Alt text

Original Readme​

note

VoloGen​

CI NuGet License: MIT Docs

What is VoloGen?​

VoloGen is a collection of Roslyn incremental source generators that produce standard method overloads, interface implementations, and operators from core logic you write yourself.

VoloGen is not a value-object generator. It does not create types for you, impose wrapper structures, or dictate how your domain model looks. Instead, it takes the one method you already wrote — the single source of truth for parsing, formatting, comparing, or equality — and generates every remaining overload, interface member, and operator that the .NET type system expects.

######### The idea

Every .NET interface like IParsable\<T\>, IComparable\<T\>, or IEquatable\<T\> demands multiple method signatures that ultimately delegate to the same core logic. Writing them by hand is tedious, error-prone, and produces hundreds of lines of boilerplate that obscure the real business rules.

VoloGen flips this around:

  1. You define the core behavior — the "how" — in a single method.
  2. The generator produces all the standard overloads that delegate to your implementation.
  3. You stay in control — every generated method can be overridden by simply declaring it yourself.
┌──────────────────────────────────────────────────────────────────┐
│ Your code (the rule) │ Generated code (the overloads) │
│───────────────────────────────│─────────────────────────────────│
│ static bool TryParse(...) │ Parse(string, IFormatProvider?) │
│ │ Parse(ReadOnlySpan<char>, ...) │
│ │ TryParse(string?, ...) │
│ │ IParsable\<T\>.Parse(...) │
│ │ ISpanParsable\<T\>.Parse(...) │
│ │ IUtf8SpanParsable\<T\>.*(...) │
└──────────────────────────────────────────────────────────────────┘

Each generator ships as an independent NuGet package — use only what you need.

Full Documentation →


How it works​
You implementGenerator produces
One core method with your business logicAll standard overloads delegating to it
Nothing elseInterface implementations (IParsable\<T\>, IFormattable, etc.)
Operators (==, !=, <, >, <=, >=)
Convenience overloads (string, span, UTF-8)

The generator never invents behavior — every generated method is a thin wrapper that calls your code. If you already declared a specific overload, the generator skips it (skip-if-exists).


Features​
  • You define the rules — generators only produce overloads, never business logic.
  • Zero runtime dependency — generated code is plain C#, no base classes or helper libraries.
  • Incremental generation — only re-generates when the annotated type changes.
  • Skip-if-exists — already have a custom Equals or Parse? The generator won't overwrite it.
  • Cross-generator coordination — [AutoComparable] and [AutoEquality] cooperate on ==/!=.
  • Strong-name signed — all assemblies are signed with VoloGen.snk.
  • Localized diagnostics — error messages are translated via .resx resource files.

Packages​
PackageAttributeWhat you writeWhat gets generated
VoloGen.Parsable[AutoParsable]TryParse(ReadOnlySpan<char>, ...)Parse, TryParse overloads, IParsable\<T\>, ISpanParsable\<T\>, opt. IUtf8SpanParsable\<T\>
VoloGen.Formattable[AutoFormattable]TryFormat(Span<char>, ...)ToString, TryFormat overloads, IFormattable, ISpanFormattable, opt. IUtf8SpanFormattable
VoloGen.Comparable[AutoComparable]static int Compare(T, T)CompareTo overloads, IComparable\<T\>, IComparable, all comparison operators
VoloGen.Equality[AutoEquality]static bool Equal(T, T) + GetHashCode()Equals overloads, IEquatable\<T\>, ==/!= operators

Quick Start​

######### 1. Install

dotnet add package VoloGen.Parsable
dotnet add package VoloGen.Parsable.Generator

######### 2. Write your core logic

using VoloGen;

[AutoParsable]
public partial struct Amount
{
private readonly decimal _value;

// This is the only method you write — the single source of truth.
// The generator will produce every other Parse/TryParse overload from it.
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Amount result)
{
if (decimal.TryParse(s, provider, out var value))
{
result = new Amount \{ _value = value };
return true;
}
result = default;
return false;
}
}

######### 3. Use the generated API

// All of these are generated — each one delegates to your TryParse above.
var a = Amount.Parse("42.5");
var b = Amount.Parse("42.5".AsSpan());
bool ok = Amount.TryParse("abc", out _); // false
bool ok2 = Amount.TryParse("100", CultureInfo.InvariantCulture, out _); // true

Core method → Generated overloads​

######### AutoEquality

You writeGenerated
static bool Equal(T left, T right)bool Equals(T) — IEquatable\<T\>
override int GetHashCode()override bool Equals(object?)
operator ==, operator !=

When [AutoComparable] is also present, ==/!= are emitted by the comparable generator to ensure consistency.

######### AutoComparable

You writeGenerated
static int Compare(T left, T right)int CompareTo(T) — IComparable\<T\>
int IComparable.CompareTo(object?)
<, >, <=, >=, ==, != operators

######### AutoParsable

You writeGenerated
static bool TryParse(ReadOnlySpan<char>, IFormatProvider?, out T)Parse(string, IFormatProvider?) — throws ArgumentNullException if string arg is null (unless ThrowOnNull = false)
Parse(ReadOnlySpan<char>, IFormatProvider?)
TryParse(string?, IFormatProvider?, out T) — accepts null; converts via AsSpan()
Providerless & spanless convenience overloads
Optional flag: ImplementUtf8 = trueIUtf8SpanParsable\<T\> overloads
Optional flag: ImplementExact = trueParseExact / TryParseExact overloads
Optional flag: ThrowOnNull = falseDisables ArgumentNullException guard in Parse(string s, ...) overloads (default: true)

######### AutoFormattable

You writeGenerated
bool TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)IFormattable — ToString(string?, IFormatProvider?)
Positive MaxBufferSize attribute property, const int MaxBufferSize, or ToString(string?, IFormatProvider?)ISpanFormattable convenience overloads
override string ToString()
Optional flag: ImplementUtf8 = trueIUtf8SpanFormattable overloads
Optional flag: DefaultFormat = "G"Default format for formatless overloads
Optional flag: AllowNullFormatProvider = falseNull-provider guard with ArgumentNullException
Optional property: MaxBufferSize = 256Buffer size for generated ToString; overrides the legacy constant
Optional property: MaxStackBufferSize = 256stackalloc threshold; defaults to 256, maximum 1024

Diagnostics​

All diagnostics use the VoloGen category and are errors by default.

IDNameTrigger
VG0001MissingTryParseMethod[AutoParsable] without core TryParse
VG0002MustBePartialType is not partial
VG0003CannotBeStaticType is static
VG0004CannotBeAbstractType is abstract
VG0005MissingComparableField[AutoComparable] without Compare
VG0006MissingEquatableField[AutoEquality] without Equal / GetHashCode
VG0007MissingTryFormatMethod[AutoFormattable] without TryFormat
VG0008MissingToStringOrMaxBufferSize[AutoFormattable] without ToString or MaxBufferSize
VG0009InvalidMaxStackBufferSizeExplicit MaxStackBufferSize is non-positive, greater than 1024, or greater than MaxBufferSize

Project Structure​
VoloGen/
+-- .github/ ### CI workflows, issue templates, Copilot instructions
+-- samples/ ### End-to-end usage examples
| +-- VoloGen.Samples.Formattable/
+-- src/
| +-- VoloGen.Common/ ### Shared diagnostics, helpers, localized .resx
| +-- VoloGen.Equality/ ### [AutoEquality] attribute
| +-- VoloGen.Equality.Generator/
| +-- VoloGen.Comparable/ ### [AutoComparable] attribute
| +-- VoloGen.Comparable.Generator/
| +-- VoloGen.Parsable/ ### [AutoParsable] attribute
| +-- VoloGen.Parsable.Generator/
| +-- VoloGen.Formattable/ ### [AutoFormattable] attribute
| +-- VoloGen.Formattable.Generator/
+-- tests/
| +-- VoloGen.Equality.Tests/
| +-- VoloGen.Comparable.Tests/
| +-- VoloGen.Parsable.Tests/
| +-- VoloGen.Formattable.Tests/
| +-- VoloGen.Combinations.Tests/ ### Multi-attribute combination tests
+-- docs/ ### GitHub Pages documentation (Jekyll)
+-- build/ ### Build scripts and documentation
+-- .editorconfig ### Code style rules
+-- Directory.Build.props ### Shared MSBuild properties
+-- VoloGen.snk ### Strong-name signing key
+-- VoloGen.slnx ### Solution file

Development​

######### Prerequisites

######### Build & Test

git clone https://github.com/OleksandrTsvirkun/VoloGen.git
cd VoloGen
dotnet tool restore
dotnet husky install
dotnet build
dotnet test

######### Run Samples

dotnet run --project samples/VoloGen.Samples.Formattable

The Formattable sample demonstrates attribute-based MaxBufferSize and MaxStackBufferSize, the legacy const int MaxBufferSize fallback, generated ToString overloads, and ISpanFormattable.TryFormat.

######### Releasing

See the Release Process documentation for how to tag and publish a new version.

######### Commit Policy

This project uses Conventional Commits enforced by Husky.NET + CommitLint.NET.

Format: <type>(<scope>): <description>

Types: feat, fix, refactor, docs, test, build, ci, chore, perf, style

Scopes: parsable, formattable, comparable, equality, common, ci, readme, examples


Contributing​

Contributions are welcome! Please read the Contributing Guide before submitting a PR.

Code of Conduct​

This project follows the Contributor Covenant Code of Conduct.

Security​

To report a vulnerability, please see our Security Policy.

Acknowledgements​

Inspired by the excellent work in Vogen by Steve Dunn and StronglyTypedId by Andrew Lock.

License​

MIT -- Copyright (c) 2026 Oleksandr Tsvirkun

About​

note

Generate standard parsing overloads and interfaces from one TryParse implementation

Reduce boilerplate while keeping parsing logic under your control

How to use​

Example (source csproj, source files)​

This is the CSharp Project that references VoloGen

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

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

<ItemGroup>
<PackageReference Include="VoloGen.Parsable" Version="1.2.0" />
<PackageReference Include="VoloGen.Parsable.Generator" Version="1.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

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

</Project>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>
#nullable enable
using System;

partial struct Temperature : System.IParsable<Temperature>, System.ISpanParsable<Temperature>
{
public static Temperature Parse(string s, System.IFormatProvider? provider)
{
ValuGenThrowHelper.ThrowIfNull(s, nameof(s));
if (!TryParse(s.AsSpan(), provider, out var result))
{
ValuGenThrowHelper.ThrowFormatException("Input string was not in a correct format for type 'Temperature'.");
}

return result;
}
public static Temperature Parse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider)
{
if (!TryParse(s, provider, out var result))
{
ValuGenThrowHelper.ThrowFormatException("Input string was not in a correct format for type 'Temperature'.");
}

return result;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool TryParse(string? s, System.IFormatProvider? provider, out Temperature result)
{
return TryParse(s.AsSpan(), provider, out result);
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Temperature Parse(string s)
{
return Parse(s, null);
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Temperature Parse(System.ReadOnlySpan<char> s)
{
return Parse(s, null);
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool TryParse(string? s, out Temperature result)
{
return TryParse(s, null, out result);
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool TryParse(System.ReadOnlySpan<char> s, out Temperature result)
{
return TryParse(s, null, out result);
}

}
file static class ValuGenThrowHelper
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal static void ThrowIfNull<T>(T? argument, string paramName) where T : class
{
if (argument is null)
{
throw new System.ArgumentNullException(paramName);
}
}

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal static void ThrowFormatException(string message)
{
throw new System.FormatException(message);
}
}

Useful​

Download Example (.NET C#)​

Share VoloGen​

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

Category "EnhancementClass" has the following generators:​

1 AOP.Logging.SourceGenerator Nuget GitHub Repo stars 2026-08-30

2 ApparatusAOT Nuget GitHub Repo stars 2023-04-16

3 AspectGenerator Nuget GitHub Repo stars 2024-01-07

4 CommonCodeGenerator Nuget GitHub Repo stars 2024-04-03

5 Comparison Nuget GitHub Repo stars 2025-05-25

6 DudNet Nuget GitHub Repo stars 2023-10-27

7 Enhanced.GetTypes Nuget GitHub Repo stars 2024-09-17

8 FastGenericNew Nuget GitHub Repo stars 2023-08-10

9 Immutype Nuget GitHub Repo stars 2023-08-12

10 Incursa.Generators Nuget GitHub Repo stars 2026-11-22

11 Ling.Audit Nuget GitHub Repo stars 2023-12-12

12 Lombok.NET Nuget GitHub Repo stars 2023-04-16

13 M31.FluentAPI Nuget GitHub Repo stars 2023-08-25

14 MemberAccessor Nuget GitHub Repo stars 2025-03-24

15 MemoryPack Nuget GitHub Repo stars 2023-08-04

16 Meziantou.Polyfill Nuget GitHub Repo stars 2023-10-10

17 Microsoft.Extensions.Logging Nuget GitHub Repo stars 2023-04-16

18 Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator Nuget GitHub Repo stars 2023-11-17

19 Microsoft.Interop.JavaScript.JSImportGenerator 2023-04-16

20 NLog.Extensions.ThisClass Nuget GitHub Repo stars 2026-04-03

21 OptionToStringGenerator Nuget GitHub Repo stars 2024-02-15

22 Pekspro.DataAnnotationValuesExtractor Nuget GitHub Repo stars 2026-02-15

23 Program Nuget GitHub Repo stars 2025-11-06

24 QueryStringGenerator Nuget GitHub Repo stars 2024-11-07

25 RSCG_Decorator Nuget GitHub Repo stars 2023-09-30

26 RSCG_UtilityTypes NugetNuget GitHub Repo stars 2023-12-22

27 StaticReflection NugetNuget GitHub Repo stars 2023-10-13

28 SyncMethodGenerator Nuget GitHub Repo stars 2023-08-14

29 System.Runtime.InteropServices Nuget GitHub Repo stars 2023-04-16

30 System.Text.RegularExpressions Nuget GitHub Repo stars 2023-04-16

31 TelemetryLogging Nuget GitHub Repo stars 2023-11-30

32 Tenekon.MethodOverloads.SourceGenerator Nuget GitHub Repo stars 2026-09-05

33 ThisClass Nuget GitHub Repo stars 2024-04-19

34 TrimItEasy Nuget GitHub Repo stars 2026-08-28

35 VoloGen NugetNuget GitHub Repo stars 2026-11-19

See category​

EnhancementClass