Repository navigation
Add union type support - #123
Merged
Merged
Conversation
4 tasks done
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical generated-code failures and additional union validation, accessibility, and nullable-handling issues remain unresolved.
Review effort: Lite
Findings: 3
Open (4)
What changed in this PR
Adds source-generated serialization support for custom and C# union types.
Changes:
- Adds union analysis, metadata, diagnostics, formatter generation, and registration.
- Adds custom, generic, class-based, typed-storage, and .NET 11 union tests.
- Updates NativeAOT samples, project targets, and CI for .NET 11.
| File | Summary |
|---|---|
tests/CsToml.Tests/CsToml.Tests.csproj |
Adds .NET 11 test targeting. |
tests/CsToml.Generator.Tests/Generator/UnionTest.cs |
Tests custom union behavior. |
tests/CsToml.Generator.Tests/Generator/Net11/UnionNet11Test.cs |
Tests .NET 11 union syntax. |
tests/CsToml.Generator.Tests/Declarations/UnionDeclarations.cs |
Defines custom union fixtures. |
tests/CsToml.Generator.Tests/Declarations/UnionAttributePolyfill.cs |
Provides union attribute support for older targets. |
tests/CsToml.Generator.Tests/Declarations/Net11/UnionNet11Declarations.cs |
Defines .NET 11 union fixtures. |
tests/CsToml.Generator.Tests/CsToml.Generator.Tests.csproj |
Adds .NET 11 test targeting. |
tests/CsToml.Extensions.Configuration.Tests/CsToml.Extensions.Configuration.Tests.csproj |
Adds .NET 11 test targeting. |
src/CsToml.Generator/UnionSymbolAnalyzer.cs |
Detects unions and providers; provider validation and formatter-name collision handling require changes. |
src/CsToml.Generator/UnionMetaFactory.cs |
Builds union formatter metadata; nested unpinned cases and containing generic parameters require changes. |
src/CsToml.Generator/UnionMeta.cs |
Defines union metadata models. |
src/CsToml.Generator/TypeMeta.cs |
Integrates unions into object metadata; invalid pins can produce a duplicate diagnostic. |
src/CsToml.Generator/TomlValueFormatterResolverEmitter.cs |
Emits union formatter registrations. |
src/CsToml.Generator/TomlSerializationKind.cs |
Adds union serialization classification. |
src/CsToml.Generator/SymbolUtility.cs |
Resolves union pins and reachable types. |
src/CsToml.Generator/Generator.cs |
Emits union formatters and registration; class-union formatter typing and standalone accessibility require changes. |
src/CsToml.Generator/FormatterTypeMetaData.cs |
Classifies union serialization types; nullable unions can lose pinned-case serialization style. |
src/CsToml.Generator/DiagnosticDescriptors.cs |
Adds union diagnostics. |
sandbox/ConsoleNativeAOT/Union.cs |
Adds a NativeAOT union sample. |
sandbox/ConsoleNativeAOT/Program.cs |
Exercises union serialization. |
sandbox/ConsoleNativeAOT/ConsoleNativeAOT.csproj |
Retargets the sample to .NET 11. |
.github/workflows/build.yml |
Installs the .NET 11 SDK in CI. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.


This PR adds
uniontype support.Support:
uniondeclarations[System.Runtime.CompilerServices.Union]TryGetValue(out T)and optionalHasValue)IUnionMembers,IUnionMembers.Create(value))[Union])usage
Related
#121