Add XML namespace support for Choice properties - #21
Merged
Conversation
GregoryNikolaishvili
commented
Aug 1, 2026
Contributor
- Support XmlTag.Namespace for per-property XML namespaces
- Emit [XmlElement(..., Namespace=...)] for correct XML output
- Serialize only the active choice property (no xsi:nil)
- Add advanced XML serialization tests with namespaces
- Add envelope and document models for test coverage
- Update tests for mixed XmlTag/XmlElement and namespaces
- Bump version to 2.2.0
- Support XmlTag.Namespace for per-property XML namespaces - Emit [XmlElement(..., Namespace=...)] for correct XML output - Serialize only the active choice property (no xsi:nil) - Add advanced XML serialization tests with namespaces - Add envelope and document models for test coverage - Update tests for mixed XmlTag/XmlElement and namespaces - Bump version to 2.2.0
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the Choice source generator’s XML serialization support by allowing per-property XML namespaces (via XmlTag.Namespace) and by tightening XML output so only the active choice property is serialized (avoiding xsi:nil for inactive choices). It also adds a set of namespace-focused serialization tests and updates the package version.
Changes:
- Add
Namespacesupport toXmlTagAttributeand propagate it into generated[XmlElement(..., Namespace = ...)]attributes. - Generate
ShouldSerialize{Property}()methods for choice properties to ensure only the active choice serializes (noxsi:nilfor inactive choices). - Add/expand XML serialization tests covering namespaces, envelope/document structures, and nil suppression; bump version to
2.2.0.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/AltaSoft.ChoiceGenerator.Tests/XmlNamespaceNilTests.cs | Adds regression tests asserting no xsi:nil and no inactive choice elements are emitted. |
| tests/AltaSoft.ChoiceGenerator.Tests/XmlNamespaceChoice.cs | Introduces a Choice model using XmlTag.Namespace for per-property namespaces. |
| tests/AltaSoft.ChoiceGenerator.Tests/XmlChoiceSerializationTests.cs | Adds comprehensive XML round-trip tests for multiple choice shapes and edge cases. |
| tests/AltaSoft.ChoiceGenerator.Tests/ChoiceGeneratorTests.cs | Adds namespace round-trip tests for XmlNamespaceChoice. |
| tests/AltaSoft.ChoiceGenerator.Tests/AdvancedXmlNamespaceTests.cs | Adds advanced envelope/document namespace tests and nil suppression checks. |
| tests/AltaSoft.ChoiceGenerator.Tests/AdvancedXml/* | Adds XML models used for advanced namespace/envelope serialization coverage. |
| tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/* | Updates/introduces snapshots reflecting namespace emission and ShouldSerialize behavior changes. |
| tests/AltaSoft.Choice.Generator.SnapshotTests/ChoiceGeneratorTest.cs | Adds snapshot test cases for XmlTag.Namespace and mixed attribute scenarios. |
| src/AltaSoft.Choice/XmlTagAttribute.cs | Adds Namespace property to XmlTagAttribute. |
| src/AltaSoft.Choice.Generator/Models/PropertyDetails.cs | Stores per-property XML namespace metadata for generation. |
| src/AltaSoft.Choice.Generator/Executor.cs | Emits [XmlElement(..., Namespace=...)] and generates ShouldSerialize{Property} methods for choices. |
| Directory.Build.props | Bumps version to 2.2.0 and updates copyright years. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.