From 83e5cd4f875504f8758cdd5a602bef6072b68c88 Mon Sep 17 00:00:00 2001 From: Ewout Kramer Date: Tue, 19 Nov 2024 18:02:11 +0100 Subject: [PATCH] Stop generating Children/NamedChildren. --- .../Language/Firely/CSharpFirely2.cs | 266 +++++++++--------- 1 file changed, 133 insertions(+), 133 deletions(-) diff --git a/src/Microsoft.Health.Fhir.CodeGen/Language/Firely/CSharpFirely2.cs b/src/Microsoft.Health.Fhir.CodeGen/Language/Firely/CSharpFirely2.cs index f23cb4df0..78a5f88d2 100644 --- a/src/Microsoft.Health.Fhir.CodeGen/Language/Firely/CSharpFirely2.cs +++ b/src/Microsoft.Health.Fhir.CodeGen/Language/Firely/CSharpFirely2.cs @@ -2013,10 +2013,10 @@ private void WriteComponent( WriteMatches(exportName, exportedElements); WriteIsExactly(exportName, exportedElements); - WriteChildren(exportName, exportedElements); - WriteNamedChildren(exportName, exportedElements); + // WriteChildren(exportName, exportedElements); + // WriteNamedChildren(exportName, exportedElements); - WriteIDictionarySupport(exportName, exportedElements); + WriteDictionarySupport(exportName, exportedElements); // close class CloseScope(); @@ -2073,7 +2073,7 @@ private string DetermineExportedBaseTypeName(string baseTypeName) return baseTypeName; } - private void WriteIDictionarySupport(string exportName, List exportedElements) + private void WriteDictionarySupport(string exportName, List exportedElements) { WriteDictionaryTryGetValue(exportName, exportedElements); WriteDictionaryTrySetValue(exportName, exportedElements); @@ -2096,7 +2096,7 @@ private void WriteDictionaryPairs(string exportName, List ex return; } - _writer.WriteLineIndented("protected override IEnumerable> GetElementPairs()"); + _writer.WriteLineIndented("internal protected override IEnumerable> GetElementPairs()"); OpenScope(); _writer.WriteLineIndented("foreach (var kvp in base.GetElementPairs()) yield return kvp;"); @@ -2112,7 +2112,7 @@ private void WriteDictionaryPairs(string exportName, List ex private void WriteDictionaryTryGetValue(string exportName, List exportedElements) { - // Base implementation differs from subclasses and is hand-written code in a separate partical class + // Base implementation differs from subclasses and is hand-written code in a separate partial class if (exportName == "Base") { return; @@ -2124,7 +2124,7 @@ private void WriteDictionaryTryGetValue(string exportName, ListWrites the children of this item. /// Name of the exported class. /// The exported elements. - private void WriteNamedChildren(string exportName, - List exportedElements) - { - // Base implementation differs from subclasses. - if (exportName == "Base") - { - _writer.WriteIndentedComment(""" - Enumerate all child nodes. - Return a sequence of child elements, components and/or properties. - Child nodes are returned as tuples with the name and the node itself, in the order defined - by the FHIR specification. - First returns child nodes inherited from any base class(es), recursively. - Finally returns child nodes defined by the current class. - """); - _writer.WriteLineIndented("[IgnoreDataMember]"); - _writer.WriteLineIndented("public virtual IEnumerable NamedChildren => Enumerable.Empty();"); - _writer.WriteLine(string.Empty); - return; - } - - // Don't override anything if there are no additional elements. - if (!exportedElements.Any()) - { - return; - } - - _writer.WriteLineIndented("[IgnoreDataMember]"); - _writer.WriteLineIndented("public override IEnumerable NamedChildren"); - - OpenScope(); - _writer.WriteLineIndented("get"); - OpenScope(); - _writer.WriteLineIndented($"foreach (var item in base.NamedChildren) yield return item;"); - - foreach (WrittenElementInfo info in exportedElements) - { - if (info.PropertyType is ListTypeReference) - { - _writer.WriteLineIndented( - $"foreach (var elem in {info.PropertyName})" + - $" {{ if (elem != null)" + - $" yield return new ElementValue(\"{info.FhirElementName}\", elem);" + - $" }}"); - } - else - { - string yr = NamedChildrenFhirTypeWrapper(info); - - _writer.WriteLineIndented( - $"if ({info.PropertyName} != null)" + - $" yield return new ElementValue(\"{info.FhirElementName}\", {yr});"); - } - } - - CloseScope(suppressNewline: true); - CloseScope(); - } + // private void WriteNamedChildren(string exportName, + // List exportedElements) + // { + // // Base implementation differs from subclasses. + // if (exportName == "Base") + // { + // _writer.WriteIndentedComment(""" + // Enumerate all child nodes. + // Return a sequence of child elements, components and/or properties. + // Child nodes are returned as tuples with the name and the node itself, in the order defined + // by the FHIR specification. + // First returns child nodes inherited from any base class(es), recursively. + // Finally returns child nodes defined by the current class. + // """); + // _writer.WriteLineIndented("[IgnoreDataMember]"); + // _writer.WriteLineIndented("public virtual IEnumerable NamedChildren => Enumerable.Empty();"); + // _writer.WriteLine(string.Empty); + // return; + // } + // + // // Don't override anything if there are no additional elements. + // if (!exportedElements.Any()) + // { + // return; + // } + // + // _writer.WriteLineIndented("[IgnoreDataMember]"); + // _writer.WriteLineIndented("public override IEnumerable NamedChildren"); + // + // OpenScope(); + // _writer.WriteLineIndented("get"); + // OpenScope(); + // _writer.WriteLineIndented($"foreach (var item in base.NamedChildren) yield return item;"); + // + // foreach (WrittenElementInfo info in exportedElements) + // { + // if (info.PropertyType is ListTypeReference) + // { + // _writer.WriteLineIndented( + // $"foreach (var elem in {info.PropertyName})" + + // $" {{ if (elem != null)" + + // $" yield return new ElementValue(\"{info.FhirElementName}\", elem);" + + // $" }}"); + // } + // else + // { + // string yr = NamedChildrenFhirTypeWrapper(info); + // + // _writer.WriteLineIndented( + // $"if ({info.PropertyName} != null)" + + // $" yield return new ElementValue(\"{info.FhirElementName}\", {yr});"); + // } + // } + // + // CloseScope(suppressNewline: true); + // CloseScope(); + // } // For a limited set of exceptional elements, the Children functions return a // complex FHIR type wrapper. - private static string NamedChildrenFhirTypeWrapper(WrittenElementInfo info) - { - - return info.FhirElementPath switch - { - "Narrative.div" => $"new FhirString({info.PropertyName}.Value)", - "Element.id" => $"new FhirString({info.PropertyName})", - "Extension.url" => $"new FhirUri({info.PropertyName})", - _ => $"{info.PropertyName}" - }; - } + // private static string NamedChildrenFhirTypeWrapper(WrittenElementInfo info) + // { + // + // return info.FhirElementPath switch + // { + // "Narrative.div" => $"new FhirString({info.PropertyName}.Value)", + // "Element.id" => $"new FhirString({info.PropertyName})", + // "Extension.url" => $"new FhirUri({info.PropertyName})", + // _ => $"{info.PropertyName}" + // }; + // } /// Writes the children of this item. /// Name of the exported class. /// The exported elements. - private void WriteChildren(string exportName, - List exportedElements) - { - // Base implementation differs from subclasses. - if (exportName == "Base") - { - _writer.WriteIndentedComment( - """ - Enumerate all child nodes. - Return a sequence of child elements, components and/or properties. - Child nodes are returned in the order defined by the FHIR specification. - First returns child nodes inherited from any base class(es), recursively. - Finally returns child nodes defined by the current class. - """); - _writer.WriteLineIndented("[IgnoreDataMember]"); - _writer.WriteLineIndented("public virtual IEnumerable Children => Enumerable.Empty();"); - _writer.WriteLine(string.Empty); - return; - } - - // Don't override anything if there are no additional elements. - if (!exportedElements.Any()) - { - return; - } - - _writer.WriteLineIndented("[IgnoreDataMember]"); - _writer.WriteLineIndented("public override IEnumerable Children"); - - OpenScope(); - _writer.WriteLineIndented("get"); - OpenScope(); - _writer.WriteLineIndented($"foreach (var item in base.Children) yield return item;"); - - foreach (WrittenElementInfo info in exportedElements) - { - if (info.PropertyType is ListTypeReference) - { - _writer.WriteLineIndented( - $"foreach (var elem in {info.PropertyName})" + - $" {{ if (elem != null) yield return elem; }}"); - } - else - { - string yr = NamedChildrenFhirTypeWrapper(info); - _writer.WriteLineIndented( - $"if ({info.PropertyName} != null)" + - $" yield return {yr};"); - } - } - - CloseScope(suppressNewline: true); - CloseScope(); - } + // private void WriteChildren(string exportName, + // List exportedElements) + // { + // // Base implementation differs from subclasses. + // if (exportName == "Base") + // { + // _writer.WriteIndentedComment( + // """ + // Enumerate all child nodes. + // Return a sequence of child elements, components and/or properties. + // Child nodes are returned in the order defined by the FHIR specification. + // First returns child nodes inherited from any base class(es), recursively. + // Finally returns child nodes defined by the current class. + // """); + // _writer.WriteLineIndented("[IgnoreDataMember]"); + // _writer.WriteLineIndented("public virtual IEnumerable Children => Enumerable.Empty();"); + // _writer.WriteLine(string.Empty); + // return; + // } + // + // // Don't override anything if there are no additional elements. + // if (!exportedElements.Any()) + // { + // return; + // } + // + // _writer.WriteLineIndented("[IgnoreDataMember]"); + // _writer.WriteLineIndented("public override IEnumerable Children"); + // + // OpenScope(); + // _writer.WriteLineIndented("get"); + // OpenScope(); + // _writer.WriteLineIndented($"foreach (var item in base.Children) yield return item;"); + // + // foreach (WrittenElementInfo info in exportedElements) + // { + // if (info.PropertyType is ListTypeReference) + // { + // _writer.WriteLineIndented( + // $"foreach (var elem in {info.PropertyName})" + + // $" {{ if (elem != null) yield return elem; }}"); + // } + // else + // { + // string yr = NamedChildrenFhirTypeWrapper(info); + // _writer.WriteLineIndented( + // $"if ({info.PropertyName} != null)" + + // $" yield return {yr};"); + // } + // } + // + // CloseScope(suppressNewline: true); + // CloseScope(); + // } /// Writes the matches. /// Name of the exported class. @@ -2664,9 +2664,9 @@ private void WriteBackboneComponent( { WriteMatches(exportName, exportedElements); WriteIsExactly(exportName, exportedElements); - WriteChildren(exportName, exportedElements); - WriteNamedChildren(exportName, exportedElements); - WriteIDictionarySupport(exportName, exportedElements); + //WriteChildren(exportName, exportedElements); + //WriteNamedChildren(exportName, exportedElements); + WriteDictionarySupport(exportName, exportedElements); } // close class