Skip to content

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

Merged
merged 8 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)]";
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.

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<string> 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<TypedQName, Dictionary<TypedQName, List<string>>> _attributeData =
new Dictionary<TypedQName, Dictionary<TypedQName, 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<TypedQName, 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",
// 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<TypedQName, List<string>>()
{
{
"c:CT_PictureOptions/c:pictureOptions",
ObsoletePropertyWarnList
},
}
},
{
"c:CT_LineSer/c15:ser",
new Dictionary<TypedQName, List<string>>()
{
{
"c:CT_PictureOptions/c:pictureOptions",
ObsoletePropertyWarnList
},
}
},
{
"c:CT_PieSer/c15:ser",
new Dictionary<TypedQName, List<string>>()
{
{
"c:CT_PictureOptions/c:pictureOptions",
ObsoletePropertyWarnList
},
}
},
{
"c:CT_RadarSer/c15:ser",
new Dictionary<TypedQName, List<string>>()
{
{
"c:CT_PictureOptions/c:pictureOptions",
ObsoletePropertyWarnList
},
}
},
{
"c:CT_SurfaceSer/c15:ser",
new Dictionary<TypedQName, List<string>>()
{
{
"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))
Expand Down Expand Up @@ -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<TypedQName, 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, out List<string> attributeStrings))
{
foreach (string attributeString in attributeStrings)
{
writer.WriteLine(attributeString);
}
}
}

writer.Write("public ");

if (element.IsAbstract)
Expand Down Expand Up @@ -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<TypedQName, List<string>> attrAttributeData)
&& attrAttributeData.TryGetValue(":" + attribute.Type + "/" + attribute.QName.ToString(), out List<string> attrAttributeStrings))
{
writer.WriteAttributeProperty(services, attribute, attrAttributeStrings);
}
else
{
writer.WriteAttributeProperty(services, attribute);
}
}

delimiter.AddDelimiter();
Expand All @@ -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<TypedQName, List<string>> childAttributeData)
&& childAttributeData.TryGetValue(node.Name, out List<string> childAttributeStrings))
{
writer.WriteElement(services, element, node, ref delimiter, childAttributeStrings);
}
else
{
writer.WriteElement(services, element, node, ref delimiter);
}
}
}

Expand Down Expand Up @@ -298,7 +435,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))
{
Expand All @@ -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("? ");
Expand All @@ -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<string>? attributeStrings = null)
{
var remarks = default(string);
var info = services.GetNamespaceInfo(attribute.QName.Prefix);
Expand All @@ -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("? ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2542,6 +2542,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.Marker? Marker
/// <remarks>
/// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart
/// </remarks>
[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<DocumentFormat.OpenXml.Drawing.Charts.PictureOptions>();
Expand Down Expand Up @@ -3034,6 +3036,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro
/// <remarks>
/// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart
/// </remarks>
[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<DocumentFormat.OpenXml.Drawing.Charts.PictureOptions>();
Expand Down Expand Up @@ -3220,6 +3224,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro
/// <remarks>
/// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart
/// </remarks>
[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<DocumentFormat.OpenXml.Drawing.Charts.PictureOptions>();
Expand Down Expand Up @@ -3394,6 +3400,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro
/// <remarks>
/// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart
/// </remarks>
[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<DocumentFormat.OpenXml.Drawing.Charts.PictureOptions>();
Expand Down Expand Up @@ -3562,6 +3570,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.ChartShapeProperties? ChartShapePro
/// <remarks>
/// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart
/// </remarks>
[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<DocumentFormat.OpenXml.Drawing.Charts.PictureOptions>();
Expand Down Expand Up @@ -3601,6 +3611,8 @@ public DocumentFormat.OpenXml.Drawing.Charts.Values? Values
/// <remarks>
/// xmlns:c = http://schemas.openxmlformats.org/drawingml/2006/chart
/// </remarks>
[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<DocumentFormat.OpenXml.Drawing.Charts.Bubble3D>();
Expand Down
Loading