Add EnumValue adapter property for simpleContent enum restrictions#578
Merged
Add EnumValue adapter property for simpleContent enum restrictions#578
Conversation
Co-authored-by: mganss <976344+mganss@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #578 +/- ##
==========================================
+ Coverage 94.33% 94.36% +0.03%
==========================================
Files 32 32
Lines 3230 3338 +108
Branches 515 526 +11
==========================================
+ Hits 3047 3150 +103
- Misses 122 123 +1
- Partials 61 65 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixed the issue where generating enums for simpleContent complex types with restrictions broke existing tests. The C# XmlSerializer has limitations that prevent derived classes from adding new XmlText properties when the base class already has one. Solution: Generate the enum type for simpleContent restrictions, but don't add a new Value property in the derived class. Users can manually convert between the inherited string Value and the enum type. - Updated ClassModel.cs to not generate Value property in derived classes with simpleContent enum restrictions - Updated test to verify enum generation without expecting a strongly-typed Value property - All originally failing tests now pass (TestSimple, TestEmptyKeyProviderGeneratorPrefix, AirspaceServicesTest1) Co-authored-by: mganss <976344+mganss@users.noreply.github.com>
- Moved comment explaining enum generation to proper location outside if block - Added null safety checks for qualifiedName in CreateSimpleContentEnumModel - Improved code clarity and safety Co-authored-by: mganss <976344+mganss@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Continue work on issue #577 to fix issue #561
Fix enum generation for simpleContent restrictions to work with XmlSerializer constraints
Dec 30, 2025
Owner
|
@copilot There should be an adapter property as suggested in #562 like this: [System.Xml.Serialization.XmlIgnore]
public TransConfirmationCodeTypeEnum? EnumValue
{
get
{
if (Enum.TryParse(typeof(TransConfirmationCodeTypeEnum), Value, true, out var result))
{
return (TransConfirmationCodeTypeEnum)result;
}
return null;
}
set
{
Value = value?.ToString(); // keep Value updated
}
} |
Added an adapter property as suggested in #562 that provides strongly-typed access to enum values while keeping the string Value property for XML serialization. The EnumValue property: - Is marked with [XmlIgnore] to prevent serialization - Returns nullable enum type - Uses Enum.TryParse in getter to convert from string Value - Updates Value in setter by calling ToString() on the enum Example generated code: ```csharp [XmlIgnore] public TransConfirmationCodeTypeEnum? EnumValue { get { if (Enum.TryParse(typeof(TransConfirmationCodeTypeEnum), Value, true, out var result)) return (TransConfirmationCodeTypeEnum)result; return null; } set { Value = value?.ToString(); } } ``` Co-authored-by: mganss <976344+mganss@users.noreply.github.com>
Contributor
Author
... Added the EnumValue adapter property as suggested. The property:
Commit: 3c93a82 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Copilot
AI
changed the title
Fix enum generation for simpleContent restrictions to work with XmlSerializer constraints
Add EnumValue adapter property for simpleContent enum restrictions
Dec 30, 2025
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.
PR #577 broke three tests by attempting to add XmlText properties in derived classes when the base class already has one—a constraint the C# XmlSerializer enforces strictly.
Changes
ModelBuilder.cs
ClassModel.TextValueTypefor derived classesClassModel.cs
EnumValueadapter property for derived classes with simpleContent enum restrictions[XmlIgnore]to prevent serialization conflictsXmlTests.cs
TestSimpleContentEnumto verify enum generation and EnumValue adapter property functionalityGenerated Code
Usage
This approach generates the requested enum types and provides convenient strongly-typed access while staying within XmlSerializer's inheritance constraints.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.