Skip to content

Conversation

@tomjebo
Copy link
Collaborator

@tomjebo tomjebo commented Mar 21, 2025

this pr obsoletes the properties mentioned in #1769
it also adds code to the generator to add code attributes like ObsoleteAttribute to complex type classes, child elements and attributes.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR obsoletes several child elements and updates the code generator to add attributes such as ObsoleteAttribute to complex type classes, child elements, and attributes.

  • Introduces a new dictionary (_attributeData) to map fully qualified names to attribute annotations.
  • Extends signature of WriteType, WriteElement, and WriteAttributeProperty methods to conditionally emit additional attribute strings.
Comments suppressed due to low confidence (2)

gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs:196

  • [nitpick] The variable name 'ctAttributeData' is ambiguous; consider renaming it to something like 'classAttributeAnnotations' to more clearly indicate its purpose.
if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary<string, List<string>> ctAttributeData))

gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs:244

  • [nitpick] The variable name 'attrAttributeData' could be renamed to something like 'attributeAnnotations' for clarity, making it easier to distinguish from the class-level attribute data.
if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary<string, List<string>> attrAttributeData)

@github-actions
Copy link

github-actions bot commented Mar 21, 2025

Test Results

    56 files   -   1      56 suites   - 1   55m 33s ⏱️ + 2m 1s
 2 042 tests ±  0   2 039 ✅ ±  0   3 💤 ±0  0 ❌ ±0 
31 781 runs   - 517  31 745 ✅  - 517  36 💤 ±0  0 ❌ ±0 

Results for commit 316a9ef. ± Comparison against base commit f990ae8.

♻️ This comment has been updated with latest results.

mikeebowen
mikeebowen previously approved these changes Mar 21, 2025
twsouthwick
twsouthwick previously approved these changes Mar 24, 2025
{
{
"c:CT_PictureOptions/c:pictureOptions",
new List<string>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are duplicated, so it may be nice to have a readonly static list that can be reused

delimiter.AddDelimiter();
writer.WriteAttributeProperty(services, attribute);

if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary<string, List<string>> attrAttributeData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could make the dictionary have the type of element.Name (I think it's a TypedQName) and it'll make it a bit more performant. The keys you're creating will also automatically be converted to it as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, that was a good idea. for SchemaAttributes, they aren't actually TypedQName but I decided to try using the Type property of the attribute metadata to construct a string that can convert to a TypedQName for the purposes of keys in the dictionary. It was either that or string.Empty which would have issues in parsing. So even though the Type property of the attribute metadata is actually the c# type (class), it works. If you have an alternative suggestion I'll try that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to have the C# type class - it would be nice to have that a completely separate thing.

@tomjebo tomjebo dismissed stale reviews from twsouthwick and mikeebowen via 4e84bbf March 26, 2025 01:04
{
public static class AttributeStrings
{
public const string ObsoletePropertyWarn = "[Obsolete(\"Unused property, will be removed in a future version.\", false)]";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all these? looks like only two are used

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not right now, but I added them to make clear the distinction in the different types of obsolescence so we follow some pattern in naming.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm seems like a lot of duplicated text. You can use $"{}" in consts to reduce that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but I prefer to compose them from smallerbits of text to ensure they're built up the same.

@tomjebo tomjebo merged commit ac4882d into dotnet:main Mar 27, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants