Fixes a code generation bug failed to generate the required XName fields in a C# class for an element#90
Open
mamift wants to merge 13 commits into
Open
Fixes a code generation bug failed to generate the required XName fields in a C# class for an element#90mamift wants to merge 13 commits into
mamift wants to merge 13 commits into
Conversation
…pace ends with Xml or System, this causes compiler errors due to ambiguity.
…r occurred; this is necessary to distinguish identifiers that really do have numbers in their name, from identifiers that have simply have had numbers appended as suffix due to name collisions.
…bug in paraparse.
Fixed the following bug: when an element definition is of a type that itself inherits from another type, the static xname fields do not properly get generated as part of the element dictionary (BuildElementDictionary) which is called in the static constructor for the that element class.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an XObjectsCodeGen code-generation defect where wrapper element types could miss required static XName fields for content-model properties when the wrapped type participates in an inheritance chain. It also adds a repro/generated schema project (ParaParserXml) and bumps the package version to v3.4.16.
Changes:
- Ensure
XNamefields are generated even when the property originates from a base type (so wrapper element types don’t rely on content-type inheritance). - Adjust generated
usingimports to addglobal::when the generated CLR namespace would otherwise create ambiguity (notably when it ends withSystem/Xml). - Add
ParaParserXmlgenerated schema library + solution/test suite wiring; bump version and update release notes.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| XObjectsCode/Src/TypesToCodeDom.cs | Adds namespace-import disambiguation for generated code namespaces (prefix global:: when needed). |
| XObjectsCode/Src/TypeBuilder.cs | Refactors local element dictionary property generation and minor CodeDOM statement construction changes. |
| XObjectsCode/Src/PropertyBuilder.cs | Fixes missing XName field generation by not skipping base-origin properties. |
| XObjectsCode/Src/NameMangler.cs | Refactors local symbol generation (adds SymbolIdentifier and adjusts collision handling helpers). |
| Version.props | Bumps package version to 3.4.16. |
| RELEASENOTES.md | Adds a new release entry for the change (needs a small correction per review comments). |
| LinqToXsdCore.sln | Adds ParaParserXml project and updates solution metadata. |
| LinqToXsd/Properties/launchSettings.json | Adds a launch profile to generate code for paraparse.xsd. |
| LinqToXsd-TestingSuite.slnf | Includes the new ParaParserXml project in the testing solution filter. |
| GeneratedSchemaLibraries/ParaParserXml/ParaParserXml.csproj | New generated schema library project for ParaParse; embeds schema/config/generated code. |
| GeneratedSchemaLibraries/ParaParserXml/paraparse.xsd.config | Configuration mapping urn:ParaParse.XML to ParaParse.Xml. |
| GeneratedSchemaLibraries/ParaParserXml/paraparse.xsd | Full ParaParse schema used for generation/regression coverage. |
| GeneratedSchemaLibraries/ParaParserXml/paraparse_xNameBug.xsd | Minimal repro schema for the missing-XName bug scenario. |
| GeneratedSchemaLibraries/ParaParserXml/paraparse_xNameBug.xsd.cs | Generated output for the minimal repro schema. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * https://www.nuget.org/packages/LinqToXsdCore/3.4.16 | ||
| * https://www.nuget.org/packages/XObjectsCore/3.4.16 | ||
| * [#88](https://github.com/mamift/LinqToXsdCore/pull/90). | ||
| * Fixed a code gen issue when an element definition is of a type that itself inherits from another type, the static `XName` fields that are usually generated for properties that are part of the element's content model, do not get generated at all. These are part of the element dictionary (`BuildElementDictionary()`) which is called in the static constructor for the that element class. This bug affects `XObjectsCodeGen`. Affected code generation for *paraparse.xsd*. |
Comment on lines
+669
to
+671
| // at this point we need to check if adding global:: to any of the above namespace imports is necessary to avoid ambiguity with the | ||
| // generated code namespace. specifically what this fixes is that if the clrNamespace ends in a word that equals one of the starting | ||
| // words above (System or Xml), then a compiler errors are more likely to occur due to ambiguity between the namespace import and the generated code namespace |
Comment on lines
+12
to
+15
| <ItemGroup> | ||
| <None Remove="paraparse.xsd" /> | ||
| <None Remove="paraparse.xsd.config" /> | ||
| </ItemGroup> |
PR suggestion Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Fixed a code gen issue when an element definition is of a type that itself inherits from another type, the static
XNamefields that are usually generated for properties that are part of the element's content model, do not get generated at all. These are part of the element dictionary (BuildElementDictionary()) which is called in the static constructor for the that element class. This bug affectsXObjectsCodeGen. Affected code generation for paraparse.xsd.v3.4.16