-
Notifications
You must be signed in to change notification settings - Fork 586
obsolete several child elements removed in Office 2015 #1905
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
Changes from 2 commits
3064c57
9baba68
fc643e2
4e84bbf
8804cac
e60b953
6a66c77
316a9ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<string, Dictionary<string, List<string>>> _attributeData = | ||
| new Dictionary<string, Dictionary<string, List<string>>>() | ||
| { | ||
| // 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<string, List<string>>() | ||
| // { | ||
| // { | ||
| // 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<string>() | ||
| // { | ||
| // "[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<string>() | ||
| // { | ||
| // "[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<string>() | ||
| // { | ||
| // "[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<string, List<string>>() | ||
| { | ||
| { | ||
| "c:CT_PictureOptions/c:pictureOptions", | ||
| new List<string>() | ||
| { | ||
| "[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<string, List<string>>() | ||
| { | ||
| { | ||
| "c:CT_PictureOptions/c:pictureOptions", | ||
| new List<string>() | ||
| { | ||
| "[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<string, List<string>>() | ||
| { | ||
| { | ||
| "c:CT_PictureOptions/c:pictureOptions", | ||
| new List<string>() | ||
| { | ||
| "[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<string, List<string>>() | ||
| { | ||
| { | ||
| "c:CT_PictureOptions/c:pictureOptions", | ||
| new List<string>() | ||
| { | ||
| "[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<string, List<string>>() | ||
| { | ||
| { | ||
| "c:CT_PictureOptions/c:pictureOptions", | ||
| new List<string>() | ||
| { | ||
| "[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<string>() | ||
| { | ||
| "[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<string, List<string>> 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<string> 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<string, List<string>> attrAttributeData) | ||
|
||
| && attrAttributeData.TryGetValue(attribute.QName.ToString(), out List<string> 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<string, List<string>> childAttributeData) | ||
| && childAttributeData.TryGetValue(node.Name.ToString(), out List<string> 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<Validator> 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<string>? 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<string>? 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("? "); | ||
|
|
||
There was a problem hiding this comment.
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