From 3064c5743d732bb44907b15ad43acd95d9b32e93 Mon Sep 17 00:00:00 2001 From: Tom Jebo Date: Thu, 20 Mar 2025 19:07:15 -0700 Subject: [PATCH 1/7] obsolete several child elements removed in Office 2015 --- .../Elements/DataModelWriterExtensions.cs | 181 +++++++++++++++++- ...crosoft_com_office_drawing_2012_chart.g.cs | 12 ++ 2 files changed, 189 insertions(+), 4 deletions(-) diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index 37de9ac8d..e6a6d18e8 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -11,6 +11,132 @@ namespace DocumentFormat.OpenXml.Generator.Generators.Elements; public static class DataModelWriterExtensions { + // Use this dictionary to add attributes like ObsoleteAttribute or other directives to classes, child elements or attributes. + private static readonly Dictionary>> _attributeData = + new Dictionary>>() + { + // Example with annotations: + // { + // This is the containing complex type class, in the json metadata, this comes from the fully qualified "Name": "c:CT_BubbleSer/c15:ser", + // "c:CT_BubbleSer/c15:ser", + // new Dictionary>() + // { + // { + // This is an example of obsoleting the whole class. + // In the json metadata: + // Use the same fully qualified name as the class, for example "Name": "c:CT_BubbleSer/c15:ser", + // "c:CT_BubbleSer/c15:ser", + // new List() + // { + // "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + // "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + // } + // }, + // { + // This is an example obsoleting a child element (property in C#) + // In the json metadata: + // For child elements, this comes from "Name": "c:CT_PictureOptions/c:pictureOptions", + // "c:CT_PictureOptions/c:pictureOptions", + // new List() + // { + // "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + // "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + // } + // }, + // { + // This is an example obsoleting a child attribute (property in C#) + // In the json metadata: use for example "QName": ":formatCode", + // ":formatCode", + // new List() + // { + // "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + // "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + // } + // }, + // } + // }, + { + "c:CT_BubbleSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + new List() + { + "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + } + }, + } + }, + { + "c:CT_LineSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + new List() + { + "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + } + }, + } + }, + { + "c:CT_PieSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + new List() + { + "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + } + }, + } + }, + { + "c:CT_RadarSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + new List() + { + "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + } + }, + } + }, + { + "c:CT_SurfaceSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + new List() + { + "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + } + }, + { + "c:CT_Boolean/c:bubble3D", + new List() + { + "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", + "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + } + }, + } + }, + }; + + private static string _elementAttributeStrings = string.Empty; + public static bool GetDataModelSyntax(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaNamespace model) { foreach (var ns in GetNamespaces(model, services).Distinct().OrderBy(n => n)) @@ -66,6 +192,20 @@ private static string GetBaseName(SchemaType type) private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaType element) { writer.WriteDocumentationComment(BuildTypeComments(services, element)); + + if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> ctAttributeData)) + { + // if the fully qualified CT/tag name is also one of the children of the dictionary that means the attributes of that + // child's list need to be applied to the whole class, for example, if we're obsoleting an entire class. + if (ctAttributeData.TryGetValue(element.Name.ToString(), out List attributeStrings)) + { + foreach (string attributeString in attributeStrings) + { + writer.WriteLine(attributeString); + } + } + } + writer.Write("public "); if (element.IsAbstract) @@ -100,7 +240,16 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe foreach (var attribute in element.Attributes) { delimiter.AddDelimiter(); - writer.WriteAttributeProperty(services, attribute); + + if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> attrAttributeData) + && attrAttributeData.TryGetValue(attribute.QName.ToString(), out List attrAttributeStrings)) + { + writer.WriteAttributeProperty(services, attribute, attrAttributeStrings); + } + else + { + writer.WriteAttributeProperty(services, attribute); + } } delimiter.AddDelimiter(); @@ -110,7 +259,15 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe { foreach (var node in element.Children) { - writer.WriteElement(services, element, node, ref delimiter); + if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> childAttributeData) + && childAttributeData.TryGetValue(node.Name.ToString(), out List childAttributeStrings)) + { + writer.WriteElement(services, element, node, ref delimiter, childAttributeStrings); + } + else + { + writer.WriteElement(services, element, node, ref delimiter); + } } } @@ -298,7 +455,7 @@ void WriteUnion(IndentedTextWriter writer, string name, IEnumerable v } } - private static void WriteElement(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaType parent, SchemaElement element, ref Delimiter delimiter) + private static void WriteElement(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaType parent, SchemaElement element, ref Delimiter delimiter, List? attributeStrings = null) { if (string.IsNullOrEmpty(element.PropertyName)) { @@ -320,6 +477,14 @@ private static void WriteElement(this IndentedTextWriter writer, OpenXmlGenerato Remarks = $"xmlns:{element.Name.QName.Prefix} = {services.GetNamespaceInfo(element.Name.QName.Prefix).Uri}", }); + if (attributeStrings is not null) + { + foreach (string attributeString in attributeStrings) + { + writer.WriteLine(attributeString); + } + } + writer.Write("public "); writer.Write(className); writer.Write("? "); @@ -335,7 +500,7 @@ private static void WriteElement(this IndentedTextWriter writer, OpenXmlGenerato } } - private static void WriteAttributeProperty(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaAttribute attribute) + private static void WriteAttributeProperty(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaAttribute attribute, List? attributeStrings = null) { var remarks = default(string); var info = services.GetNamespaceInfo(attribute.QName.Prefix); @@ -359,6 +524,14 @@ private static void WriteAttributeProperty(this IndentedTextWriter writer, OpenX Remarks = remarks, }); + if (attributeStrings is not null) + { + foreach (string attributeString in attributeStrings) + { + writer.WriteLine(attributeString); + } + } + writer.Write("public "); writer.Write(attribute.Type); writer.Write("? "); diff --git a/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs b/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs index 20f341329..8aa3d016e 100644 --- a/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs +++ b/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs @@ -2542,6 +2542,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.Marker? Marker /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// + [Obsolete("Unused property, will be removed in the next major version.", false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { get => GetElement(); @@ -3034,6 +3036,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// + [Obsolete("Unused property, will be removed in the next major version.", false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { get => GetElement(); @@ -3220,6 +3224,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// + [Obsolete("Unused property, will be removed in the next major version.", false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { get => GetElement(); @@ -3394,6 +3400,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// + [Obsolete("Unused property, will be removed in the next major version.", false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { get => GetElement(); @@ -3562,6 +3570,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// + [Obsolete("Unused property, will be removed in the next major version.", false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { get => GetElement(); @@ -3601,6 +3611,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.Values? Values /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// + [Obsolete("Unused property, will be removed in the next major version.", false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.Bubble3D? Bubble3D { get => GetElement(); From 9baba68a360e04091370e132856f09e2902eac86 Mon Sep 17 00:00:00 2001 From: Tom Jebo Date: Fri, 21 Mar 2025 11:46:30 -0700 Subject: [PATCH 2/7] fix SA errors about trailing spaces --- .../Generators/Elements/DataModelWriterExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index e6a6d18e8..391ed50f5 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -18,7 +18,7 @@ public static class DataModelWriterExtensions // Example with annotations: // { // This is the containing complex type class, in the json metadata, this comes from the fully qualified "Name": "c:CT_BubbleSer/c15:ser", - // "c:CT_BubbleSer/c15:ser", + // "c:CT_BubbleSer/c15:ser", // new Dictionary>() // { // { @@ -195,8 +195,8 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> ctAttributeData)) { - // if the fully qualified CT/tag name is also one of the children of the dictionary that means the attributes of that - // child's list need to be applied to the whole class, for example, if we're obsoleting an entire class. + // if the fully qualified CT/tag name is also one of the children of the dictionary that means the attributes of that + // child's list need to be applied to the whole class, for example, if we're obsoleting an entire class. if (ctAttributeData.TryGetValue(element.Name.ToString(), out List attributeStrings)) { foreach (string attributeString in attributeStrings) From 4e84bbfb325b9d16659194b4ed1da3eaf756f07c Mon Sep 17 00:00:00 2001 From: Tom Jebo Date: Tue, 25 Mar 2025 18:03:41 -0700 Subject: [PATCH 3/7] create attribute strings --- .../Elements/DataModelWriterExtensions.cs | 35 ++++++++++++------- ...crosoft_com_office_drawing_2012_chart.g.cs | 12 +++---- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index 391ed50f5..f61d0c223 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -11,6 +11,17 @@ namespace DocumentFormat.OpenXml.Generator.Generators.Elements; public static class DataModelWriterExtensions { + public static class AttributeStrings + { + public const string ObsoletePropertyWarn = "[Obsolete(\"Unused property, will be removed in a future version.\", false)]"; + public const string ObsoletePropertyError = "[Obsolete(\"Unused property, will be removed in a future version.\", true)]"; + public const string ObsoleteAttributeWarn = "[Obsolete(\"Unused attribute, will be removed in a future version.\", false)]"; + public const string ObsoleteAttributeError = "[Obsolete(\"Unused attribute, will be removed in a future version.\", true)]"; + public const string EditorBrowsableAlways = "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] "; + public const string EditorBrowsableAdvanced = "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] "; + public const string EditorBrowsableNever = "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] "; + } + // Use this dictionary to add attributes like ObsoleteAttribute or other directives to classes, child elements or attributes. private static readonly Dictionary>> _attributeData = new Dictionary>>() @@ -63,8 +74,8 @@ public static class DataModelWriterExtensions "c:CT_PictureOptions/c:pictureOptions", new List() { - "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + AttributeStrings.ObsoletePropertyWarn, + AttributeStrings.EditorBrowsableNever, } }, } @@ -77,8 +88,8 @@ public static class DataModelWriterExtensions "c:CT_PictureOptions/c:pictureOptions", new List() { - "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + AttributeStrings.ObsoletePropertyWarn, + AttributeStrings.EditorBrowsableNever, } }, } @@ -91,8 +102,8 @@ public static class DataModelWriterExtensions "c:CT_PictureOptions/c:pictureOptions", new List() { - "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + AttributeStrings.ObsoletePropertyWarn, + AttributeStrings.EditorBrowsableNever, } }, } @@ -105,8 +116,8 @@ public static class DataModelWriterExtensions "c:CT_PictureOptions/c:pictureOptions", new List() { - "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + AttributeStrings.ObsoletePropertyWarn, + AttributeStrings.EditorBrowsableNever, } }, } @@ -119,16 +130,16 @@ public static class DataModelWriterExtensions "c:CT_PictureOptions/c:pictureOptions", new List() { - "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + AttributeStrings.ObsoletePropertyWarn, + AttributeStrings.EditorBrowsableNever, } }, { "c:CT_Boolean/c:bubble3D", new List() { - "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", + AttributeStrings.ObsoletePropertyWarn, + AttributeStrings.EditorBrowsableNever, } }, } diff --git a/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs b/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs index 8aa3d016e..b7507700d 100644 --- a/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs +++ b/generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_microsoft_com_office_drawing_2012_chart.g.cs @@ -2542,7 +2542,7 @@ public DocumentFormat.OpenXml.Drawing.Charts.Marker? Marker /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// - [Obsolete("Unused property, will be removed in the next major version.", false)] + [Obsolete("Unused property, will be removed in a future version.", false)] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { @@ -3036,7 +3036,7 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// - [Obsolete("Unused property, will be removed in the next major version.", false)] + [Obsolete("Unused property, will be removed in a future version.", false)] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { @@ -3224,7 +3224,7 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// - [Obsolete("Unused property, will be removed in the next major version.", false)] + [Obsolete("Unused property, will be removed in a future version.", false)] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { @@ -3400,7 +3400,7 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// - [Obsolete("Unused property, will be removed in the next major version.", false)] + [Obsolete("Unused property, will be removed in a future version.", false)] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { @@ -3570,7 +3570,7 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// - [Obsolete("Unused property, will be removed in the next major version.", false)] + [Obsolete("Unused property, will be removed in a future version.", false)] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.PictureOptions? PictureOptions { @@ -3611,7 +3611,7 @@ public DocumentFormat.OpenXml.Drawing.Charts.Values? Values /// /// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart /// - [Obsolete("Unused property, will be removed in the next major version.", false)] + [Obsolete("Unused property, will be removed in a future version.", false)] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.Bubble3D? Bubble3D { From 8804cac77f0a495136c874ab6129f1379aa7fee7 Mon Sep 17 00:00:00 2001 From: Tom Jebo Date: Tue, 25 Mar 2025 18:23:13 -0700 Subject: [PATCH 4/7] remove duplicate list construction --- .../Elements/DataModelWriterExtensions.cs | 62 +++++-------------- 1 file changed, 15 insertions(+), 47 deletions(-) diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index f61d0c223..ec6b9356a 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -22,6 +22,12 @@ public static class AttributeStrings public const string EditorBrowsableNever = "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] "; } + private static readonly List ObsoletePropertyWarnList = + [ + AttributeStrings.ObsoletePropertyWarn, + AttributeStrings.EditorBrowsableNever, + ]; + // Use this dictionary to add attributes like ObsoleteAttribute or other directives to classes, child elements or attributes. private static readonly Dictionary>> _attributeData = new Dictionary>>() @@ -37,32 +43,20 @@ public static class AttributeStrings // In the json metadata: // Use the same fully qualified name as the class, for example "Name": "c:CT_BubbleSer/c15:ser", // "c:CT_BubbleSer/c15:ser", - // new List() - // { - // "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - // "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", - // } + // ObsoleteClassErrorList // }, // { // This is an example obsoleting a child element (property in C#) // In the json metadata: // For child elements, this comes from "Name": "c:CT_PictureOptions/c:pictureOptions", // "c:CT_PictureOptions/c:pictureOptions", - // new List() - // { - // "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - // "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", - // } + // ObsoletePropertyWarnList // }, // { // This is an example obsoleting a child attribute (property in C#) // In the json metadata: use for example "QName": ":formatCode", // ":formatCode", - // new List() - // { - // "[Obsolete(\"Unused property, will be removed in the next major version.\", false)]", - // "[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] ", - // } + // ObsoleteAttributeWarnList // }, // } // }, @@ -72,11 +66,7 @@ public static class AttributeStrings { { "c:CT_PictureOptions/c:pictureOptions", - new List() - { - AttributeStrings.ObsoletePropertyWarn, - AttributeStrings.EditorBrowsableNever, - } + ObsoletePropertyWarnList }, } }, @@ -86,11 +76,7 @@ public static class AttributeStrings { { "c:CT_PictureOptions/c:pictureOptions", - new List() - { - AttributeStrings.ObsoletePropertyWarn, - AttributeStrings.EditorBrowsableNever, - } + ObsoletePropertyWarnList }, } }, @@ -100,11 +86,7 @@ public static class AttributeStrings { { "c:CT_PictureOptions/c:pictureOptions", - new List() - { - AttributeStrings.ObsoletePropertyWarn, - AttributeStrings.EditorBrowsableNever, - } + ObsoletePropertyWarnList }, } }, @@ -114,11 +96,7 @@ public static class AttributeStrings { { "c:CT_PictureOptions/c:pictureOptions", - new List() - { - AttributeStrings.ObsoletePropertyWarn, - AttributeStrings.EditorBrowsableNever, - } + ObsoletePropertyWarnList }, } }, @@ -128,26 +106,16 @@ public static class AttributeStrings { { "c:CT_PictureOptions/c:pictureOptions", - new List() - { - AttributeStrings.ObsoletePropertyWarn, - AttributeStrings.EditorBrowsableNever, - } + ObsoletePropertyWarnList }, { "c:CT_Boolean/c:bubble3D", - new List() - { - AttributeStrings.ObsoletePropertyWarn, - AttributeStrings.EditorBrowsableNever, - } + ObsoletePropertyWarnList }, } }, }; - private static string _elementAttributeStrings = string.Empty; - public static bool GetDataModelSyntax(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaNamespace model) { foreach (var ns in GetNamespaces(model, services).Distinct().OrderBy(n => n)) From e60b9537bc0adc2c2e4934a54e3ef55b09afc65d Mon Sep 17 00:00:00 2001 From: Tom Jebo Date: Wed, 26 Mar 2025 11:10:39 -0700 Subject: [PATCH 5/7] use TypedQName for dictionary key --- .../Elements/DataModelWriterExtensions.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index ec6b9356a..935f2aec2 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -29,14 +29,14 @@ public static class AttributeStrings ]; // Use this dictionary to add attributes like ObsoleteAttribute or other directives to classes, child elements or attributes. - private static readonly Dictionary>> _attributeData = - new Dictionary>>() + private static readonly Dictionary>> _attributeData = + new Dictionary>>() { // Example with annotations: // { // This is the containing complex type class, in the json metadata, this comes from the fully qualified "Name": "c:CT_BubbleSer/c15:ser", // "c:CT_BubbleSer/c15:ser", - // new Dictionary>() + // new Dictionary>() // { // { // This is an example of obsoleting the whole class. @@ -62,7 +62,7 @@ public static class AttributeStrings // }, { "c:CT_BubbleSer/c15:ser", - new Dictionary>() + new Dictionary>() { { "c:CT_PictureOptions/c:pictureOptions", @@ -72,7 +72,7 @@ public static class AttributeStrings }, { "c:CT_LineSer/c15:ser", - new Dictionary>() + new Dictionary>() { { "c:CT_PictureOptions/c:pictureOptions", @@ -82,7 +82,7 @@ public static class AttributeStrings }, { "c:CT_PieSer/c15:ser", - new Dictionary>() + new Dictionary>() { { "c:CT_PictureOptions/c:pictureOptions", @@ -92,7 +92,7 @@ public static class AttributeStrings }, { "c:CT_RadarSer/c15:ser", - new Dictionary>() + new Dictionary>() { { "c:CT_PictureOptions/c:pictureOptions", @@ -102,7 +102,7 @@ public static class AttributeStrings }, { "c:CT_SurfaceSer/c15:ser", - new Dictionary>() + new Dictionary>() { { "c:CT_PictureOptions/c:pictureOptions", @@ -172,7 +172,7 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe { writer.WriteDocumentationComment(BuildTypeComments(services, element)); - if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> ctAttributeData)) + if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> ctAttributeData)) { // if the fully qualified CT/tag name is also one of the children of the dictionary that means the attributes of that // child's list need to be applied to the whole class, for example, if we're obsoleting an entire class. @@ -220,7 +220,7 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe { delimiter.AddDelimiter(); - if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> attrAttributeData) + if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> attrAttributeData) && attrAttributeData.TryGetValue(attribute.QName.ToString(), out List attrAttributeStrings)) { writer.WriteAttributeProperty(services, attribute, attrAttributeStrings); @@ -238,7 +238,7 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe { foreach (var node in element.Children) { - if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> childAttributeData) + if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> childAttributeData) && childAttributeData.TryGetValue(node.Name.ToString(), out List childAttributeStrings)) { writer.WriteElement(services, element, node, ref delimiter, childAttributeStrings); From 6a66c77909aa05875158a87fb9b75d5097047b0f Mon Sep 17 00:00:00 2001 From: Tom Jebo Date: Wed, 26 Mar 2025 12:05:12 -0700 Subject: [PATCH 6/7] resolve QName/TypedQName for XML attributes --- .../Elements/DataModelWriterExtensions.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index 935f2aec2..fe6065232 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -54,8 +54,8 @@ public static class AttributeStrings // }, // { // This is an example obsoleting a child attribute (property in C#) - // In the json metadata: use for example "QName": ":formatCode", - // ":formatCode", + // In the json metadata: use for example "QName" converted to a TypedQName string: "/:formatCode", + // "/:formatCode", // ObsoleteAttributeWarnList // }, // } @@ -172,11 +172,11 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe { writer.WriteDocumentationComment(BuildTypeComments(services, element)); - if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> ctAttributeData)) + if (_attributeData.TryGetValue(element.Name, out Dictionary> ctAttributeData)) { // if the fully qualified CT/tag name is also one of the children of the dictionary that means the attributes of that // child's list need to be applied to the whole class, for example, if we're obsoleting an entire class. - if (ctAttributeData.TryGetValue(element.Name.ToString(), out List attributeStrings)) + if (ctAttributeData.TryGetValue(element.Name, out List attributeStrings)) { foreach (string attributeString in attributeStrings) { @@ -220,8 +220,8 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe { delimiter.AddDelimiter(); - if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> attrAttributeData) - && attrAttributeData.TryGetValue(attribute.QName.ToString(), out List attrAttributeStrings)) + if (_attributeData.TryGetValue(element.Name, out Dictionary> attrAttributeData) + && attrAttributeData.TryGetValue(attribute.Type + "/" + attribute.QName.ToString(), out List attrAttributeStrings)) { writer.WriteAttributeProperty(services, attribute, attrAttributeStrings); } @@ -238,8 +238,8 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe { foreach (var node in element.Children) { - if (_attributeData.TryGetValue(element.Name.ToString(), out Dictionary> childAttributeData) - && childAttributeData.TryGetValue(node.Name.ToString(), out List childAttributeStrings)) + if (_attributeData.TryGetValue(element.Name, out Dictionary> childAttributeData) + && childAttributeData.TryGetValue(node.Name, out List childAttributeStrings)) { writer.WriteElement(services, element, node, ref delimiter, childAttributeStrings); } From 316a9efe19eab700e9ea4778a6fbb393ef4a0452 Mon Sep 17 00:00:00 2001 From: Tom Jebo Date: Wed, 26 Mar 2025 13:09:41 -0700 Subject: [PATCH 7/7] XML attribute type fix up --- .../Generators/Elements/DataModelWriterExtensions.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index fe6065232..16e6cc5bf 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -54,8 +54,9 @@ public static class AttributeStrings // }, // { // This is an example obsoleting a child attribute (property in C#) - // In the json metadata: use for example "QName" converted to a TypedQName string: "/:formatCode", - // "/:formatCode", + // In the json metadata: use for example "QName" converted to a TypedQName string using the C# type from the + // Type property with no prefix: ":StringValue/:formatCode", + // ":StringValue/:formatCode", // ObsoleteAttributeWarnList // }, // } @@ -221,7 +222,7 @@ private static void WriteType(this IndentedTextWriter writer, OpenXmlGeneratorSe delimiter.AddDelimiter(); if (_attributeData.TryGetValue(element.Name, out Dictionary> attrAttributeData) - && attrAttributeData.TryGetValue(attribute.Type + "/" + attribute.QName.ToString(), out List attrAttributeStrings)) + && attrAttributeData.TryGetValue(":" + attribute.Type + "/" + attribute.QName.ToString(), out List attrAttributeStrings)) { writer.WriteAttributeProperty(services, attribute, attrAttributeStrings); }