You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Removed from `UnionAttribute` because it has no effect on regular unions
* Added test for non-generic ad hoc union and keyed value object
* Added test classes using the new attribute (smoke test)
* Updated docs
Copy file name to clipboardExpand all lines: CLAUDE.md
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ This is a .NET library providing **Smart Enums**, **Value Objects**, and **Discr
22
22
23
23
### Core Components
24
24
-**`src/Thinktecture.Runtime.Extensions`**: Core library with base interfaces, attributes, and runtime helpers
25
-
- Attributes: `SmartEnumAttribute<TKey>`, `SmartEnumAttribute`, `ValueObjectAttribute<TKey>`, `ComplexValueObjectAttribute`, `UnionAttribute<T1,T2,...>` (up to 5 type parameters), `UnionAttribute`, `ObjectFactoryAttribute<T>`
25
+
- Attributes: `SmartEnumAttribute<TKey>`, `SmartEnumAttribute`, `ValueObjectAttribute<TKey>`, `ComplexValueObjectAttribute`, `UnionAttribute<T1,T2,...>` (up to 5 type parameters), `AdHocUnionAttribute` (non-generic alternative to UnionAttribute), `UnionAttribute`, `ObjectFactoryAttribute<T>`
@@ -53,7 +53,8 @@ The `Thinktecture.Runtime.Extensions.SourceGenerator` project contains multiple
53
53
- Supports arithmetic operators (`+`, `-`, `*`, `/`) when configured
54
54
- Integrates with serializers (JSON, MessagePack, Newtonsoft.Json)
55
55
56
-
3.**`AdHocUnionSourceGenerator`**: Generates code for ad-hoc unions annotated with `[Union<T1, T2, ...>]` (up to 5 types)
56
+
3.**`AdHocUnionSourceGenerator`**: Generates code for ad-hoc unions annotated with `[Union<T1, T2, ...>]` or `[AdHocUnion(typeof(T1), typeof(T2), ...)]` (up to 5 types)
57
+
- Supports both generic and non-generic attribute syntaxes (identical functionality)
57
58
- Creates implicit conversion operators for each union member type
58
59
- Generates exhaustive `Switch`/`Map` methods for pattern matching
59
60
- Provides type-safe value access with `IsT1`, `AsT1` properties and methods
@@ -147,16 +148,22 @@ The `Thinktecture.Runtime.Extensions.SourceGenerator` project contains multiple
147
148
**Common settings**:
148
149
-`SkipFactoryMethods`: Skip generation of `Create`, `TryCreate`, `Validate`
-`SkipEqualityComparison`: Skip generation of equality members (`Equals`, `GetHashCode`, `==`, `!=`, `IEquatable<T>`) - also sets `ComparisonOperators` and `EqualityComparisonOperators` to `None`
150
152
- Validation: Implement `ValidateFactoryArguments` (preferred) or `ValidateConstructorArguments`
151
153
152
154
#### 3. Discriminated Unions
153
-
**Ad-hoc Unions**: `[Union<T1, T2>]` through `[Union<T1, T2, T3, T4, T5>]`
155
+
**Ad-hoc Unions**: `[Union<T1, T2>]` through `[Union<T1, T2, T3, T4, T5>]` OR `[AdHocUnion(typeof(T1), typeof(T2), ...)]`
154
156
- Simple combination of 2-5 types without inheritance
157
+
- Two syntaxes available:
158
+
-**Generic** (recommended): `[Union<string, int>]` - simpler syntax for most cases
159
+
-**Non-generic**: `[AdHocUnion(typeof(string), typeof(int))]` - use when generic attribute limitations are hit (e.g., nullable reference types in generic collections like `List<string?>`, or other C# generic attribute constraints)
160
+
- Both syntaxes generate identical functionality and support the same customization options
155
161
- Generates implicit conversion operators from each type to union (configurable via `ConversionFromValue`)
156
162
- Type checking: `IsT1`, `IsT2`, etc. properties
157
163
- Value access: `AsT1`, `AsT2`, etc. properties (throws if wrong type)
158
164
- Configurable member names: `T1Name`, `T2Name`, etc.
159
165
- Nullable reference types: `T1IsNullableReferenceType`, `T2IsNullableReferenceType`, etc.
166
+
-`SkipEqualityComparison`: Skip generation of equality members (`Equals`, `GetHashCode`, `==`, `!=`, `IEquatable<T>`) for ad-hoc unions only
160
167
- Supports `Switch`/`Map` methods for exhaustive pattern matching
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_skip_equals_method_with_SkipEqualityComparison_using_non_generic_AdHocUnionAttribute.verified.txt
-47Lines changed: 0 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,6 @@ namespace Thinktecture.Tests
5
5
{
6
6
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("ThinktectureRuntimeExtensionsAnalyzer", "TTRESG1000:Internal Thinktecture.Runtime.Extensions API usage")]
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.cs
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -551,4 +551,22 @@ public partial class TestUnion;
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/ValueObjectSourceGeneratorTests.Should_not_generate_equals_method_if_SkipEqualsMethod_is_true.verified.txt
0 commit comments