VoloGen by Oleksandr Tsvirkun
NuGet / site data
Details
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/
Author
Oleksandr Tsvirkun

Original Readme
VoloGen
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:
- You define the core behavior — the "how" — in a single method.
- The generator produces all the standard overloads that delegate to your implementation.
- 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.
How it works
| You implement | Generator produces |
|---|---|
| One core method with your business logic | All standard overloads delegating to it |
| Nothing else | Interface 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
EqualsorParse? 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
.resxresource files.
Packages
| Package | Attribute | What you write | What 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 write | Generated |
|---|---|
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 write | Generated |
|---|---|
static int Compare(T left, T right) | int CompareTo(T) — IComparable\<T\> |
int IComparable.CompareTo(object?) | |
<, >, <=, >=, ==, != operators |
######### AutoParsable
| You write | Generated |
|---|---|
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 = true | IUtf8SpanParsable\<T\> overloads |
Optional flag: ImplementExact = true | ParseExact / TryParseExact overloads |
Optional flag: ThrowOnNull = false | Disables ArgumentNullException guard in Parse(string s, ...) overloads (default: true) |
######### AutoFormattable
| You write | Generated |
|---|---|
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 = true | IUtf8SpanFormattable overloads |
Optional flag: DefaultFormat = "G" | Default format for formatless overloads |
Optional flag: AllowNullFormatProvider = false | Null-provider guard with ArgumentNullException |
Optional property: MaxBufferSize = 256 | Buffer size for generated ToString; overrides the legacy constant |
Optional property: MaxStackBufferSize = 256 | stackalloc threshold; defaults to 256, maximum 1024 |
Diagnostics
All diagnostics use the VoloGen category and are errors by default.
| ID | Name | Trigger |
|---|---|---|
| VG0001 | MissingTryParseMethod | [AutoParsable] without core TryParse |
| VG0002 | MustBePartial | Type is not partial |
| VG0003 | CannotBeStatic | Type is static |
| VG0004 | CannotBeAbstract | Type is abstract |
| VG0005 | MissingComparableField | [AutoComparable] without Compare |
| VG0006 | MissingEquatableField | [AutoEquality] without Equal / GetHashCode |
| VG0007 | MissingTryFormatMethod | [AutoFormattable] without TryFormat |
| VG0008 | MissingToStringOrMaxBufferSize | [AutoFormattable] without ToString or MaxBufferSize |
| VG0009 | InvalidMaxStackBufferSize | Explicit 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
- .NET 10 SDK or later
- Git
######### 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
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)
- CSharp Project
- Program.cs
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>
This is the use of VoloGen in Program.cs
using VoloGen;
var temperature = Temperature.Parse("36.6");
Console.WriteLine($"Temperature: {temperature}");
var boiling = Temperature.Parse("100".AsSpan());
Console.WriteLine($"Boiling: {boiling}");
if (Temperature.TryParse("-40", out var cold))
{
Console.WriteLine($"Cold: {cold}");
}
if (!Temperature.TryParse("not-a-number", out _))
{
Console.WriteLine("not-a-number: invalid");
}
[AutoParsable]
public readonly partial struct Temperature : IParsable<Temperature>, ISpanParsable<Temperature>
{
public Temperature(double celsius)
{
Celsius = celsius;
}
public double Celsius \{ get; }
public static bool TryParse(ReadOnlySpan<char> text, IFormatProvider? provider, out Temperature result)
{
if (double.TryParse(text, provider, out var value))
{
result = new Temperature(value);
return true;
}
result = default;
return false;
}
public override string ToString() => $"{Celsius:F1} deg C";
}
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- Temperature.Parsable.g.cs
// <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
2026-08-30
2 ApparatusAOT
2023-04-16
3 AspectGenerator
2024-01-07
4 CommonCodeGenerator
2024-04-03
5 Comparison
2025-05-25
6 DudNet
2023-10-27
7 Enhanced.GetTypes
2024-09-17
8 FastGenericNew
2023-08-10
9 Immutype
2023-08-12
10 Incursa.Generators
2026-11-22
11 Ling.Audit
2023-12-12
12 Lombok.NET
2023-04-16
13 M31.FluentAPI
2023-08-25
14 MemberAccessor
2025-03-24
15 MemoryPack
2023-08-04
16 Meziantou.Polyfill
2023-10-10
17 Microsoft.Extensions.Logging
2023-04-16
18 Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator
2023-11-17
19 Microsoft.Interop.JavaScript.JSImportGenerator 2023-04-16
20 NLog.Extensions.ThisClass
2026-04-03
21 OptionToStringGenerator
2024-02-15
22 Pekspro.DataAnnotationValuesExtractor
2026-02-15
23 Program
2025-11-06
24 QueryStringGenerator
2024-11-07
25 RSCG_Decorator
2023-09-30
26 RSCG_UtilityTypes
2023-12-22
27 StaticReflection
2023-10-13
28 SyncMethodGenerator
2023-08-14
29 System.Runtime.InteropServices
2023-04-16
30 System.Text.RegularExpressions
2023-04-16
31 TelemetryLogging
2023-11-30
32 Tenekon.MethodOverloads.SourceGenerator
2026-09-05
33 ThisClass
2024-04-19
34 TrimItEasy
2026-08-28
35 VoloGen
2026-11-19