Skip to content

Add source generator for numeric wrapper boilerplate (#24)#25

Merged
KaliCZ merged 1 commit intomainfrom
claude/xenodochial-franklin-0cc16d
Apr 17, 2026
Merged

Add source generator for numeric wrapper boilerplate (#24)#25
KaliCZ merged 1 commit intomainfrom
claude/xenodochial-franklin-0cc16d

Conversation

@KaliCZ
Copy link
Copy Markdown
Owner

@KaliCZ KaliCZ commented Apr 17, 2026

Summary

  • New StrongTypes.SourceGenerators project (netstandard2.0) with an IIncrementalGenerator that emits IEquatable/IComparable/operator/conversion/Create boilerplate for types marked [NumericWrapper], plus Min/Max extensions always and Sum opt-in via GenerateSum = true.
  • [NumericWrapper] attribute added to the library; the generator detects targets by full metadata name so it works for both generic wrappers (Positive<T>) and concrete types (e.g. a user-defined PageSize).
  • Positive, NonNegative, Negative, and NonPositive migrated from ~100 lines of boilerplate each to a thin file containing only the validation logic, storage strategy, and invariant description. SumExtensions.cs is replaced by per-type generated extensions.
  • The generator DLL is packed into analyzers/dotnet/cs of Kalicz.StrongTypes.nupkg, so consumers get the generator automatically.

Resolves #24.

Test plan

  • dotnet test src/StrongTypes.Tests — 427/427 passing
  • dotnet build StrongTypes.slnx — full solution builds
  • dotnet pack src/StrongTypes — NuGet package includes analyzers/dotnet/cs/StrongTypes.SourceGenerators.dll

🤖 Generated with Claude Code

Introduces [NumericWrapper] attribute and a Roslyn IIncrementalGenerator
that emits the equality, comparison, operator, conversion, and Create
factory boilerplate for numeric strong-type wrappers. LINQ-style Min/Max
are always generated; Sum is opt-in via GenerateSum = true.

Migrates Positive<T>, NonNegative<T>, Negative<T>, and NonPositive<T>
from ~100 lines each to a single file with just the type-specific
validation and storage. SumExtensions.cs collapses into per-type
generated extensions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@KaliCZ KaliCZ self-assigned this Apr 17, 2026
@KaliCZ KaliCZ merged commit 8f5ad16 into main Apr 17, 2026
2 checks passed
@KaliCZ KaliCZ deleted the claude/xenodochial-franklin-0cc16d branch April 17, 2026 10:29
KaliCZ added a commit that referenced this pull request Apr 17, 2026
The main csproj has an Analyzer ProjectReference to
StrongTypes.SourceGenerators. With --no-build, pack still needs to
resolve project references and invokes the Build target on the
generator project, which then fails with NETSDK1085 because NoBuild is
set. Letting pack perform a (no-op incremental) build sidesteps this.

The Pack step only runs on main pushes, so PR CI never exercised it —
both #25 and #26 merged green and broke main. A follow-up should make
this fail fast in PR CI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
KaliCZ added a commit that referenced this pull request Apr 17, 2026
The main csproj has an Analyzer ProjectReference to
StrongTypes.SourceGenerators. With --no-build, pack still needs to
resolve project references and invokes the Build target on the
generator project, which then fails with NETSDK1085 because NoBuild is
set. Letting pack perform a (no-op incremental) build sidesteps this.

The Pack step only runs on main pushes, so PR CI never exercised it —
both #25 and #26 merged green and broke main. A follow-up should make
this fail fast in PR CI.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source generator to eliminate boilerplate in numeric wrapper types

1 participant