Skip to content

Commit 8e46127

Browse files
committed
ExtensionList<T> is being written for all but get and set
1 parent a437164 commit 8e46127

File tree

6 files changed

+138
-52
lines changed

6 files changed

+138
-52
lines changed

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

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,25 @@ private static void WriteMetadata(this IndentedTextWriter writer, OpenXmlGenerat
363363
var className = services.FindClassName(child);
364364

365365
writer.Write("builder.AddChild(");
366-
writer.Write(className);
366+
if (containingType.Name.QName.Name == "sldId" && containingType.Name.QName.Prefix == "p" && className == "DocumentFormat.OpenXml.Presentation.ExtensionList")
367+
{
368+
writer.Write($"{className}<DocumentFormat.OpenXml.Presentation.SlideId>");
369+
}
370+
else
371+
{
372+
writer.Write(className);
373+
}
374+
367375
writer.Write(".ElementType, static () => new ");
368-
writer.Write(className);
376+
if (containingType.Name.QName.Name == "sldId" && containingType.Name.QName.Prefix == "p" && className == "DocumentFormat.OpenXml.Presentation.ExtensionList")
377+
{
378+
writer.Write($"{className}<DocumentFormat.OpenXml.Presentation.SlideId>");
379+
}
380+
else
381+
{
382+
writer.Write(className);
383+
}
384+
369385
writer.WriteLine("());");
370386
}
371387
}
@@ -497,13 +513,37 @@ private static void WriteElement(this IndentedTextWriter writer, OpenXmlGenerato
497513
using (writer.AddBlock(new() { IncludeTrailingNewline = false }))
498514
{
499515
writer.Write("get => GetElement(");
500-
writer.Write(className);
516+
if (parent.Name.Type.Name == "CT_SlideId" && parent.Name.Type.Prefix == "p" && className == "DocumentFormat.OpenXml.Presentation.ExtensionList")
517+
{
518+
writer.Write("DocumentFormat.OpenXml.Presentation.ExtensionList<DocumentFormat.OpenXml.Presentation.SlideId>");
519+
}
520+
else
521+
{
522+
writer.Write(className);
523+
}
524+
501525
writer.Write(".ElementType) as ");
502-
writer.Write(className);
526+
if (parent.Name.Type.Name == "CT_SlideId" && parent.Name.Type.Prefix == "p" && className == "DocumentFormat.OpenXml.Presentation.ExtensionList")
527+
{
528+
writer.Write("DocumentFormat.OpenXml.Presentation.ExtensionList<DocumentFormat.OpenXml.Presentation.SlideId>");
529+
}
530+
else
531+
{
532+
writer.Write(className);
533+
}
534+
503535
writer.WriteLine(";");
504536

505537
writer.Write("set => SetElement(value, ");
506-
writer.Write(className);
538+
if (parent.Name.Type.Name == "CT_SlideId" && parent.Name.Type.Prefix == "p" && className == "DocumentFormat.OpenXml.Presentation.ExtensionList")
539+
{
540+
writer.Write("DocumentFormat.OpenXml.Presentation.ExtensionList<DocumentFormat.OpenXml.Presentation.SlideId>");
541+
}
542+
else
543+
{
544+
writer.Write(className);
545+
}
546+
507547
writer.WriteLine(".ElementType);");
508548
}
509549
}

gen/DocumentFormat.OpenXml.Generator.Models/Generators/Elements/ParticleWriterExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ private static void WriteCompositeObject(this IndentedTextWriter writer, OpenXml
6161
foreach (var item in p.Items)
6262
{
6363
list.AddDelimiter();
64-
writer.WriteItemNode(services, containingType, item);
64+
65+
if (containingType.Name.QName.Name == "sldId" && containingType.Name.QName.Prefix == "p" && item.Name.QName.Name == "extLst" && item.Name.QName.Prefix == "p")
66+
{
67+
writer.Write("new ElementParticle(DocumentFormat.OpenXml.Presentation.ExtensionList<DocumentFormat.OpenXml.Presentation.SlideId>.ElementType, 0, 1),");
68+
}
69+
else
70+
{
71+
writer.WriteItemNode(services, containingType, item);
72+
}
6573
}
6674

6775
writer.WriteLine();

generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas_openxmlformats_org_presentationml_2006_main.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11424,7 +11424,7 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
1142411424
{
1142511425
base.ConfigureMetadata(builder);
1142611426
builder.SetSchema(ElementType);
11427-
builder.AddChild(DocumentFormat.OpenXml.Presentation.ExtensionList.ElementType, static () => new DocumentFormat.OpenXml.Presentation.ExtensionList());
11427+
builder.AddChild(DocumentFormat.OpenXml.Presentation.ExtensionList<DocumentFormat.OpenXml.Presentation.SlideId>.ElementType, static () => new DocumentFormat.OpenXml.Presentation.ExtensionList<DocumentFormat.OpenXml.Presentation.SlideId>());
1142811428
builder.AddElement<SlideId>()
1142911429
.AddAttribute("id", a => a.Id, aBuilder =>
1143011430
{
@@ -11437,7 +11437,7 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
1143711437
});
1143811438
builder.Particle = new CompositeParticle.Builder(ParticleType.Sequence, 1, 1)
1143911439
{
11440-
new ElementParticle(DocumentFormat.OpenXml.Presentation.ExtensionList.ElementType, 0, 1)
11440+
new ElementParticle(DocumentFormat.OpenXml.Presentation.ExtensionList<DocumentFormat.OpenXml.Presentation.SlideId>.ElementType, 0, 1),
1144111441
};
1144211442
builder.AddConstraint(new UniqueAttributeValueConstraint(builder.CreateQName(":id"), true, null));
1144311443
builder.AddConstraint(new RelationshipExistConstraint(builder.CreateQName("r:id")));

src/DocumentFormat.OpenXml/Schema/Presentation/PresentationExtension.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using DocumentFormat.OpenXml;
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using DocumentFormat.OpenXml;
25
using DocumentFormat.OpenXml.Drawing;
36
using DocumentFormat.OpenXml.Framework;
47
using DocumentFormat.OpenXml.Framework.Metadata;
@@ -18,6 +21,17 @@
1821

1922
namespace DocumentFormat.OpenXml.Presentation;
2023

24+
/// <summary>
25+
/// Represents an extension element in a PresentationML document.
26+
/// </summary>
27+
/// <typeparam name="T">
28+
/// The type of the extension content. This allows the <c>Extension&lt;T&gt;</c> element to encapsulate any valid Open XML element as its child,
29+
/// enabling support for custom or future extensions within the presentation schema.
30+
/// </typeparam>
31+
/// <remarks>
32+
/// The <c>Extension&lt;T&gt;</c> element is used to store additional information that is not defined in the standard schema,
33+
/// typically for custom features or forward compatibility. The required <c>Uri</c> attribute identifies the type or purpose of the extension.
34+
/// </remarks>
2135
public partial class Extension<T> : OpenXmlCompositeElement
2236
{
2337
#pragma warning disable CS0109
@@ -29,36 +43,40 @@ public partial class Extension<T> : OpenXmlCompositeElement
2943
/// <summary>
3044
/// Initializes a new instance of the Extension class.
3145
/// </summary>
32-
public Extension() : base()
46+
public Extension()
47+
: base()
3348
{
3449
}
3550

3651
/// <summary>
3752
/// Initializes a new instance of the Extension class with the specified child elements.
3853
/// </summary>
3954
/// <param name="childElements">Specifies the child elements.</param>
40-
public Extension(IEnumerable<OpenXmlElement> childElements) : base(childElements)
55+
public Extension(IEnumerable<OpenXmlElement> childElements)
56+
: base(childElements)
4157
{
4258
}
4359

4460
/// <summary>
4561
/// Initializes a new instance of the Extension class with the specified child elements.
4662
/// </summary>
4763
/// <param name="childElements">Specifies the child elements.</param>
48-
public Extension(params OpenXmlElement[] childElements) : base(childElements)
64+
public Extension(params OpenXmlElement[] childElements)
65+
: base(childElements)
4966
{
5067
}
5168

5269
/// <summary>
5370
/// Initializes a new instance of the Extension class from outer XML.
5471
/// </summary>
5572
/// <param name="outerXml">Specifies the outer XML of the element.</param>
56-
public Extension(string outerXml) : base(outerXml)
73+
public Extension(string outerXml)
74+
: base(outerXml)
5775
{
5876
}
5977

6078
/// <summary>
61-
/// <para>URI</para>
79+
/// <para>Gets or sets uRI</para>
6280
/// <para>Represents the following attribute in the schema: uri</para>
6381
/// </summary>
6482
public StringValue? Uri
@@ -75,14 +93,14 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
7593
.AddAttribute("uri", a => a.Uri, aBuilder =>
7694
{
7795
aBuilder.AddValidator(RequiredValidator.Instance);
78-
aBuilder.AddValidator(new StringValidator() { IsToken = (true) });
96+
aBuilder.AddValidator(new StringValidator() { IsToken = true });
7997
});
8098
builder.Particle = new CompositeParticle.Builder(ParticleType.Sequence, 1, 1)
8199
{
82-
new AnyParticle(1, 1)
100+
new AnyParticle(1, 1),
83101
};
84102
}
85103

86104
/// <inheritdoc/>
87105
public override OpenXmlElement CloneNode(bool deep) => CloneImp<Extension>(deep);
88-
}
106+
}

src/DocumentFormat.OpenXml/Schema/Presentation/PresentationExtensionList.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using DocumentFormat.OpenXml;
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using DocumentFormat.OpenXml;
25
using DocumentFormat.OpenXml.Drawing;
36
using DocumentFormat.OpenXml.Framework;
47
using DocumentFormat.OpenXml.Framework.Metadata;
@@ -18,7 +21,20 @@
1821

1922
namespace DocumentFormat.OpenXml.Presentation;
2023

24+
/// <summary>
25+
/// Represents a list of extension elements (<c>extLst</c>) in a PresentationML document.
26+
/// </summary>
27+
/// <typeparam name="T">
28+
/// The type of extension element contained in the list. This allows the <c>ExtensionList&lt;T&gt;</c> to encapsulate any valid Open XML extension element,
29+
/// enabling support for custom or future extensions within the presentation schema.
30+
/// </typeparam>
31+
/// <remarks>
32+
/// The <c>ExtensionList&lt;T&gt;</c> element is used to store additional information that is not defined in the standard schema,
33+
/// typically for custom features or forward compatibility. Each child element is an <c>Extension</c> element.
34+
/// </remarks>
35+
#pragma warning disable SA1649 // File name should match first type name
2136
public class ExtensionList<T> : OpenXmlCompositeElement
37+
#pragma warning restore SA1649 // File name should match first type name
2238
{
2339
#pragma warning disable CS0109
2440
internal static readonly new OpenXmlQualifiedName ElementQName = new("http://schemas.openxmlformats.org/presentationml/2006/main", "extLst");
@@ -32,30 +48,32 @@ public class ExtensionList<T> : OpenXmlCompositeElement
3248
public ExtensionList()
3349
: base()
3450
{
35-
3651
}
3752

3853
/// <summary>
3954
/// Initializes a new instance of the ExtensionList class with the specified child elements.
4055
/// </summary>
4156
/// <param name="childElements">Specifies the child elements.</param>
42-
public ExtensionList(IEnumerable<OpenXmlElement> childElements) : base(childElements)
57+
public ExtensionList(IEnumerable<OpenXmlElement> childElements)
58+
: base(childElements)
4359
{
4460
}
4561

4662
/// <summary>
4763
/// Initializes a new instance of the ExtensionList class with the specified child elements.
4864
/// </summary>
4965
/// <param name="childElements">Specifies the child elements.</param>
50-
public ExtensionList(params OpenXmlElement[] childElements) : base(childElements)
66+
public ExtensionList(params OpenXmlElement[] childElements)
67+
: base(childElements)
5168
{
5269
}
5370

5471
/// <summary>
5572
/// Initializes a new instance of the ExtensionList class from outer XML.
5673
/// </summary>
5774
/// <param name="outerXml">Specifies the outer XML of the element.</param>
58-
public ExtensionList(string outerXml) : base(outerXml)
75+
public ExtensionList(string outerXml)
76+
: base(outerXml)
5977
{
6078
}
6179

@@ -70,13 +88,12 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
7088
{
7189
new CompositeParticle.Builder(ParticleType.Sequence, 1, 1)
7290
{
73-
new ElementParticle(DocumentFormat.OpenXml.Presentation.Extension.ElementType, 0, 0)
74-
}
75-
}
91+
new ElementParticle(DocumentFormat.OpenXml.Presentation.Extension.ElementType, 0, 0),
92+
},
93+
},
7694
};
7795
}
7896

7997
/// <inheritdoc/>
8098
public override OpenXmlElement CloneNode(bool deep) => CloneImp<ExtensionList>(deep);
8199
}
82-
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
using DocumentFormat.OpenXml;
2-
using DocumentFormat.OpenXml.Drawing;
3-
using DocumentFormat.OpenXml.Framework;
4-
using DocumentFormat.OpenXml.Framework.Metadata;
5-
using DocumentFormat.OpenXml.Office.PowerPoint.Y2022.M03.Main;
6-
using DocumentFormat.OpenXml.Office.PowerPoint.Y2022.M08.Main;
7-
using DocumentFormat.OpenXml.Office.PowerPoint.Y2023.M02.Main;
8-
using DocumentFormat.OpenXml.Office2010.Drawing;
9-
using DocumentFormat.OpenXml.Office2010.PowerPoint;
10-
using DocumentFormat.OpenXml.Office2013.PowerPoint;
11-
using DocumentFormat.OpenXml.Office2021.PowerPoint.Comment;
12-
using DocumentFormat.OpenXml.Packaging;
13-
using DocumentFormat.OpenXml.Validation.Schema;
14-
using DocumentFormat.OpenXml.Validation.Semantic;
15-
using System;
16-
using System.Collections.Generic;
17-
using System.IO.Packaging;
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
183

4+
////using DocumentFormat.OpenXml;
5+
////using DocumentFormat.OpenXml.Drawing;
6+
////using DocumentFormat.OpenXml.Framework;
7+
////using DocumentFormat.OpenXml.Framework.Metadata;
8+
////using DocumentFormat.OpenXml.Office.PowerPoint.Y2022.M03.Main;
9+
////using DocumentFormat.OpenXml.Office.PowerPoint.Y2022.M08.Main;
10+
////using DocumentFormat.OpenXml.Office.PowerPoint.Y2023.M02.Main;
11+
////using DocumentFormat.OpenXml.Office2010.Drawing;
12+
////using DocumentFormat.OpenXml.Office2010.PowerPoint;
13+
////using DocumentFormat.OpenXml.Office2013.PowerPoint;
14+
////using DocumentFormat.OpenXml.Office2021.PowerPoint.Comment;
15+
////using DocumentFormat.OpenXml.Packaging;
16+
////using DocumentFormat.OpenXml.Validation.Schema;
17+
////using DocumentFormat.OpenXml.Validation.Semantic;
18+
////using System;
19+
////using System.Collections.Generic;
20+
////using System.IO.Packaging;
1921

20-
namespace DocumentFormat.OpenXml.Presentation;
2122

22-
public partial class SlideId : OpenXmlCompositeElement
23-
{
24-
public DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>? ExtensionListT
25-
{
26-
get => GetElement(DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>.ElementType) as DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>;
27-
set => SetElement(value, DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>.ElementType);
28-
}
29-
}
23+
////namespace DocumentFormat.OpenXml.Presentation;
24+
25+
////public partial class SlideId : OpenXmlCompositeElement
26+
////{
27+
//// public DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>? ExtensionListT
28+
//// {
29+
//// get => GetElement(DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>.ElementType) as DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>;
30+
//// set => SetElement(value, DocumentFormat.OpenXml.Presentation.ExtensionList<SlideId>.ElementType);
31+
//// }
32+
////}

0 commit comments

Comments
 (0)