Feature/inumber generation#917
Merged
Merged
Conversation
Adds a new `NumericsGeneration` enum and configuration option that lets value objects wrapping numeric primitives opt in to implementing `INumber<T>` and the full generic math interface hierarchy. - New `NumericsGeneration` enum with `Omit` (default) and `GenerateINumberInterfaceAndMethods` - New `GenerateCodeForINumber` source generator handles interface declarations and all static members (operators, properties, helpers) - All four generators (class, struct, record class, record struct) wired up - `NumericsGeneration` parameter added to `ValueObjectAttribute<T>`, `ValueObjectAttribute`, and `VogenDefaultsAttribute`; can also be set globally via `[assembly: VogenDefaults]` - Snapshot tests covering double/int structs, double class, and custom-operator deduplication Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the two Generate options (GenerateINumberInterfaceAndMethods / GenerateINumberBaseInterfaceAndMethods) with a single Generate value that auto-detects the richest interface the underlying type supports: INumber<T> for signed/unsigned numerics, INumberBase<T> for types like Complex. Fix a compile error in the generated unary negation operator for ulong-backed value objects: C# does not allow unary minus on ulong. For all unsigned integer types (byte, ushort, uint, ulong, nuint), mirror what the BCL's IUnaryNegationOperators<T,T> does and emit unchecked(default(T) - value.Value) instead of (T)(-value.Value). Add snapshot tests for uint and ulong to cover the unsigned path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…arameter The three helper methods in VogenConfigurationTests were missing the new NumericsGeneration parameter added to the VogenConfiguration record. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
snap-v8.0 generates identical INumber code to snap-v9.0. snap-v4.8 generates plain VOs without INumber (C# 11 guard skips generation). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
virzak
force-pushed
the
feature/inumber-generation
branch
from
April 22, 2026 06:55
d606215 to
0f5dba3
Compare
- Revert Testbench to project references (local NuGet testing was transient) - Add VOG037 warning when NumericsGeneration.Generate is set on a type whose underlying primitive does not implement INumberBase<T> - Fix unary negation for byte and ushort: sub-int unsigned arithmetic promotes to int in C#, so cast back to primitiveType is required; update uint and ulong to use the same pattern for consistency - Add snapshot tests for byte, ushort, and char (char documents the intentional skip when IParsable<T> is explicit-only) - Add NumericsGenerationAnalyzerTests with 3 cases covering VOG037 (emitted for string, not emitted for double or Complex) - Document numericsGeneration in Configuration.md - Fill out Analyzer-Rules.md with the full rule table including VOG037 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
virzak
marked this pull request as ready for review
April 22, 2026 07:17
Owner
|
Excellent work, thank you very much! I'd be interested to see how you use it. |
Contributor
Author
It is used pretty much like it was described in the issue, but I'll provide a few other examples. Do you know when the next nuget release will happen? Thanks for merging! |
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #910