-
Notifications
You must be signed in to change notification settings - Fork 201
Add EnumValue adapter property for simpleContent enum restrictions #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: mganss <[email protected]>
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 <[email protected]>
- 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 <[email protected]>
|
@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 <[email protected]>
... 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:
|
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.