diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs index 37de9ac8d..16e6cc5bf 100644 --- a/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs +++ b/gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/DataModelWriterExtensions.cs @@ -11,6 +11,112 @@ 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)] "; + } + + 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>>() + { + // 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", + // 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", + // ObsoletePropertyWarnList + // }, + // { + // This is an example obsoleting a child attribute (property in C#) + // 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 + // }, + // } + // }, + { + "c:CT_BubbleSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + ObsoletePropertyWarnList + }, + } + }, + { + "c:CT_LineSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + ObsoletePropertyWarnList + }, + } + }, + { + "c:CT_PieSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + ObsoletePropertyWarnList + }, + } + }, + { + "c:CT_RadarSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + ObsoletePropertyWarnList + }, + } + }, + { + "c:CT_SurfaceSer/c15:ser", + new Dictionary>() + { + { + "c:CT_PictureOptions/c:pictureOptions", + ObsoletePropertyWarnList + }, + { + "c:CT_Boolean/c:bubble3D", + ObsoletePropertyWarnList + }, + } + }, + }; + public static bool GetDataModelSyntax(this IndentedTextWriter writer, OpenXmlGeneratorServices services, SchemaNamespace model) { foreach (var ns in GetNamespaces(model, services).Distinct().OrderBy(n => n)) @@ -66,6 +172,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, 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, out List attributeStrings)) + { + foreach (string attributeString in attributeStrings) + { + writer.WriteLine(attributeString); + } + } + } + writer.Write("public "); if (element.IsAbstract) @@ -100,7 +220,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, out Dictionary> attrAttributeData) + && attrAttributeData.TryGetValue(":" + attribute.Type + "/" + attribute.QName.ToString(), out List attrAttributeStrings)) + { + writer.WriteAttributeProperty(services, attribute, attrAttributeStrings); + } + else + { + writer.WriteAttributeProperty(services, attribute); + } } delimiter.AddDelimiter(); @@ -110,7 +239,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, out Dictionary> childAttributeData) + && childAttributeData.TryGetValue(node.Name, out List childAttributeStrings)) + { + writer.WriteElement(services, element, node, ref delimiter, childAttributeStrings); + } + else + { + writer.WriteElement(services, element, node, ref delimiter); + } } } @@ -298,7 +435,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 +457,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 +480,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 +504,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..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,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 a future 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 a future 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 a future 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 a future 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 a future 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 a future version.", false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public DocumentFormat.OpenXml.Drawing.Charts.Bubble3D? Bubble3D { get => GetElement();