Generators
VoloGen provides four independent source generators. Each one targets a specific value-object concern and ships as its own NuGet package.
| Generator | You Provide | Generator Emits |
|---|---|---|
| AutoEquality | Equal(T, T) + GetHashCode() |
IEquatable<T>, Equals(object?), ==, != |
| AutoComparable | Compare(T, T) |
IComparable<T>, IComparable, <, >, <=, >=, ==, != |
| AutoParsable | TryParse(ReadOnlySpan<char>, ...) |
IParsable<T>, ISpanParsable<T>, all Parse/TryParse overloads |
| AutoFormattable | TryFormat(Span<char>, ...) |
IFormattable, ISpanFormattable, all ToString/TryFormat overloads |
Common Rules
All generators share the following requirements:
- The type must be
partial– the generator adds members to a partial declaration - The type must not be
static– source generation targets instance types - The type must not be
abstract– concrete implementations are required
Violating these rules produces a compile-time diagnostic error. See the Diagnostics page for details.
Skip-If-Exists
Every generator checks whether an identical overload already exists on the target type before emitting it. This means you can always override any generated method by defining your own – the generator will silently skip it.
Operator Coordination
When both [AutoEquality] and [AutoComparable] are applied to the same type:
[AutoComparable]takes ownership of==and!=operators (delegating toCompare)[AutoEquality]skips those operators to avoid duplicate declarations
This coordination is automatic – no configuration needed.