Skip to content

Commit d20003e

Browse files
authored
Remove generic builder pattern from element metadata create (Part 2): AddChild (#1843)
This replaces `AddChild<T>` with a non-generic version - helps move towards less type knowledge in the system.
1 parent e069c61 commit d20003e

File tree

111 files changed

+9607
-9607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+9607
-9607
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,13 @@ private static void WriteMetadata(this IndentedTextWriter writer, OpenXmlGenerat
360360
{
361361
foreach (var child in containingType.KnownChildren)
362362
{
363-
writer.Write("builder.AddChild<");
364-
writer.Write(services.FindClassName(child));
365-
writer.WriteLine(">();");
363+
var className = services.FindClassName(child);
364+
365+
writer.Write("builder.AddChild(");
366+
writer.Write(className);
367+
writer.Write(".ElementType, static () => new ");
368+
writer.Write(className);
369+
writer.WriteLine("());");
366370
}
367371
}
368372

generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas-microsoft-com_office_excel.g.cs

Lines changed: 67 additions & 67 deletions
Large diffs are not rendered by default.

generated/DocumentFormat.OpenXml/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/schemas-microsoft-com_office_office.g.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,17 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
194194
{
195195
base.ConfigureMetadata(builder);
196196
builder.SetSchema(ElementType);
197-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Callout>();
198-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.ColorMenu>();
199-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.ColorMostRecentlyUsed>();
200-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Extrusion>();
201-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Lock>();
202-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Skew>();
203-
builder.AddChild<DocumentFormat.OpenXml.Vml.Fill>();
204-
builder.AddChild<DocumentFormat.OpenXml.Vml.ImageData>();
205-
builder.AddChild<DocumentFormat.OpenXml.Vml.Shadow>();
206-
builder.AddChild<DocumentFormat.OpenXml.Vml.Stroke>();
207-
builder.AddChild<DocumentFormat.OpenXml.Vml.TextBox>();
197+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Callout.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Callout());
198+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.ColorMenu.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.ColorMenu());
199+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.ColorMostRecentlyUsed.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.ColorMostRecentlyUsed());
200+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Extrusion.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Extrusion());
201+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Lock.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Lock());
202+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Skew.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Skew());
203+
builder.AddChild(DocumentFormat.OpenXml.Vml.Fill.ElementType, static () => new DocumentFormat.OpenXml.Vml.Fill());
204+
builder.AddChild(DocumentFormat.OpenXml.Vml.ImageData.ElementType, static () => new DocumentFormat.OpenXml.Vml.ImageData());
205+
builder.AddChild(DocumentFormat.OpenXml.Vml.Shadow.ElementType, static () => new DocumentFormat.OpenXml.Vml.Shadow());
206+
builder.AddChild(DocumentFormat.OpenXml.Vml.Stroke.ElementType, static () => new DocumentFormat.OpenXml.Vml.Stroke());
207+
builder.AddChild(DocumentFormat.OpenXml.Vml.TextBox.ElementType, static () => new DocumentFormat.OpenXml.Vml.TextBox());
208208
builder.AddElement<ShapeDefaults>()
209209
.AddAttribute("v:ext", a => a.Extension)
210210
.AddAttribute("spidmax", a => a.MaxShapeId)
@@ -448,9 +448,9 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
448448
{
449449
base.ConfigureMetadata(builder);
450450
builder.SetSchema(ElementType);
451-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.ShapeIdMap>();
452-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.RegroupTable>();
453-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Rules>();
451+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.ShapeIdMap.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.ShapeIdMap());
452+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.RegroupTable.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.RegroupTable());
453+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Rules.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Rules());
454454
builder.AddElement<ShapeLayout>()
455455
.AddAttribute("v:ext", a => a.Extension);
456456
builder.Particle = new CompositeParticle.Builder(ParticleType.All, 1, 1)
@@ -907,7 +907,7 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
907907
{
908908
base.ConfigureMetadata(builder);
909909
builder.SetSchema(ElementType);
910-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.RelationTable>();
910+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.RelationTable.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.RelationTable());
911911
builder.AddElement<Diagram>()
912912
.AddAttribute("v:ext", a => a.Extension)
913913
.AddAttribute("dgmstyle", a => a.Style)
@@ -1905,9 +1905,9 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
19051905
{
19061906
base.ConfigureMetadata(builder);
19071907
builder.SetSchema(ElementType);
1908-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.LinkType>();
1909-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.LockedField>();
1910-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.FieldCodes>();
1908+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.LinkType.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.LinkType());
1909+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.LockedField.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.LockedField());
1910+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.FieldCodes.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.FieldCodes());
19111911
builder.AddElement<OleObject>()
19121912
.AddAttribute("Type", a => a.Type)
19131913
.AddAttribute("ProgID", a => a.ProgId)
@@ -2733,7 +2733,7 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
27332733
{
27342734
base.ConfigureMetadata(builder);
27352735
builder.SetSchema(ElementType);
2736-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Entry>();
2736+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Entry.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Entry());
27372737
builder.AddElement<RegroupTable>()
27382738
.AddAttribute("v:ext", a => a.Extension);
27392739
builder.Particle = new CompositeParticle.Builder(ParticleType.Sequence, 1, 1)
@@ -2813,7 +2813,7 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
28132813
{
28142814
base.ConfigureMetadata(builder);
28152815
builder.SetSchema(ElementType);
2816-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Rule>();
2816+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Rule.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Rule());
28172817
builder.AddElement<Rules>()
28182818
.AddAttribute("v:ext", a => a.Extension);
28192819
builder.Particle = new CompositeParticle.Builder(ParticleType.Sequence, 1, 1)
@@ -2973,7 +2973,7 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
29732973
{
29742974
base.ConfigureMetadata(builder);
29752975
builder.SetSchema(ElementType);
2976-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Proxy>();
2976+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Proxy.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Proxy());
29772977
builder.AddElement<Rule>()
29782978
.AddAttribute("id", a => a.Id, aBuilder =>
29792979
{
@@ -3062,7 +3062,7 @@ internal override void ConfigureMetadata(ElementMetadata.Builder builder)
30623062
{
30633063
base.ConfigureMetadata(builder);
30643064
builder.SetSchema(ElementType);
3065-
builder.AddChild<DocumentFormat.OpenXml.Vml.Office.Relation>();
3065+
builder.AddChild(DocumentFormat.OpenXml.Vml.Office.Relation.ElementType, static () => new DocumentFormat.OpenXml.Vml.Office.Relation());
30663066
builder.AddElement<RelationTable>()
30673067
.AddAttribute("v:ext", a => a.Extension);
30683068
builder.Particle = new CompositeParticle.Builder(ParticleType.Sequence, 1, 1)

0 commit comments

Comments
 (0)