Skip to content

Commit

Permalink
Removed Children, de-duplicated some SnapshotGen files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutkramer committed Nov 19, 2024
1 parent 4d8d896 commit 6d4b929
Show file tree
Hide file tree
Showing 654 changed files with 439 additions and 82,015 deletions.
39 changes: 39 additions & 0 deletions src/Hl7.Fhir.Base/Model/Base.Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;

namespace Hl7.Fhir.Model;

public static class BaseExtensions
{
[Obsolete("Use GetElementPairs() instead. Note that with GetElementPairs(), the elements are not guaranteed to " +
"be the same type, as they reflect the type in the actual POCO definition.")]
public static IEnumerable<Base> Children(this Base instance)
{
foreach (var element in instance.GetElementPairs())
{
switch (element.Key, element.Value)
{
case ("div", XHtml xhtml):
yield return new FhirString(xhtml.Value);
break;
case ("id", string id):
yield return new FhirString(id);
break;
case ("url", string url):
yield return new FhirUri(url);
break;
case (_, IEnumerable<Base> list):
foreach (var item in list)
yield return item;
break;
case("value", _) when instance is PrimitiveType:
yield break;
default:
yield return (Base)element.Value;
break;
}
}
}
}
3 changes: 1 addition & 2 deletions src/Hl7.Fhir.Base/Model/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ POSSIBILITY OF SUCH DAMAGE.
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Utility;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;

namespace Hl7.Fhir.Model;
Expand Down Expand Up @@ -119,7 +119,6 @@ internal protected virtual bool TryGetValue(string key, [NotNullWhen(true)] out
// TODO bring Children + NamedChildren over as well.
}


/// <summary>
/// A dynamic data type that can hold any element.
/// </summary>
Expand Down
44 changes: 0 additions & 44 deletions src/Hl7.Fhir.Base/Model/Generated/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,50 +546,6 @@ public override bool IsExactly(IDeepComparable other)
return true;
}

[IgnoreDataMember]
public override IEnumerable<Base> Children
{
get
{
foreach (var item in base.Children) yield return item;
if (ContentTypeElement != null) yield return ContentTypeElement;
if (LanguageElement != null) yield return LanguageElement;
if (DataElement != null) yield return DataElement;
if (UrlElement != null) yield return UrlElement;
if (SizeElement != null) yield return SizeElement;
if (HashElement != null) yield return HashElement;
if (TitleElement != null) yield return TitleElement;
if (CreationElement != null) yield return CreationElement;
if (HeightElement != null) yield return HeightElement;
if (WidthElement != null) yield return WidthElement;
if (FramesElement != null) yield return FramesElement;
if (DurationElement != null) yield return DurationElement;
if (PagesElement != null) yield return PagesElement;
}
}

[IgnoreDataMember]
public override IEnumerable<ElementValue> NamedChildren
{
get
{
foreach (var item in base.NamedChildren) yield return item;
if (ContentTypeElement != null) yield return new ElementValue("contentType", ContentTypeElement);
if (LanguageElement != null) yield return new ElementValue("language", LanguageElement);
if (DataElement != null) yield return new ElementValue("data", DataElement);
if (UrlElement != null) yield return new ElementValue("url", UrlElement);
if (SizeElement != null) yield return new ElementValue("size", SizeElement);
if (HashElement != null) yield return new ElementValue("hash", HashElement);
if (TitleElement != null) yield return new ElementValue("title", TitleElement);
if (CreationElement != null) yield return new ElementValue("creation", CreationElement);
if (HeightElement != null) yield return new ElementValue("height", HeightElement);
if (WidthElement != null) yield return new ElementValue("width", WidthElement);
if (FramesElement != null) yield return new ElementValue("frames", FramesElement);
if (DurationElement != null) yield return new ElementValue("duration", DurationElement);
if (PagesElement != null) yield return new ElementValue("pages", PagesElement);
}
}

internal protected override bool TryGetValue(string key, out object value)
{
switch (key)
Expand Down
20 changes: 0 additions & 20 deletions src/Hl7.Fhir.Base/Model/Generated/BackboneElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,6 @@ public override bool IsExactly(IDeepComparable other)
return true;
}

[IgnoreDataMember]
public override IEnumerable<Base> Children
{
get
{
foreach (var item in base.Children) yield return item;
foreach (var elem in ModifierExtension) { if (elem != null) yield return elem; }
}
}

[IgnoreDataMember]
public override IEnumerable<ElementValue> NamedChildren
{
get
{
foreach (var item in base.NamedChildren) yield return item;
foreach (var elem in ModifierExtension) { if (elem != null) yield return new ElementValue("modifierExtension", elem); }
}
}

internal protected override bool TryGetValue(string key, out object value)
{
switch (key)
Expand Down
20 changes: 0 additions & 20 deletions src/Hl7.Fhir.Base/Model/Generated/BackboneType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,6 @@ public override bool IsExactly(IDeepComparable other)
return true;
}

[IgnoreDataMember]
public override IEnumerable<Base> Children
{
get
{
foreach (var item in base.Children) yield return item;
foreach (var elem in ModifierExtension) { if (elem != null) yield return elem; }
}
}

[IgnoreDataMember]
public override IEnumerable<ElementValue> NamedChildren
{
get
{
foreach (var item in base.NamedChildren) yield return item;
foreach (var elem in ModifierExtension) { if (elem != null) yield return new ElementValue("modifierExtension", elem); }
}
}

internal protected override bool TryGetValue(string key, out object value)
{
switch (key)
Expand Down
21 changes: 0 additions & 21 deletions src/Hl7.Fhir.Base/Model/Generated/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,6 @@ public virtual IDeepCopyable DeepCopy() =>

public virtual bool IsExactly(IDeepComparable other) => other is Base;

/// <summary>
/// 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.
/// </summary>
[IgnoreDataMember]
public virtual IEnumerable<Base> Children => Enumerable.Empty<Base>();

/// <summary>
/// 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.
/// </summary>
[IgnoreDataMember]
public virtual IEnumerable<ElementValue> NamedChildren => Enumerable.Empty<ElementValue>();

}

}
Expand Down
26 changes: 0 additions & 26 deletions src/Hl7.Fhir.Base/Model/Generated/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,32 +225,6 @@ public override bool IsExactly(IDeepComparable other)
return true;
}

[IgnoreDataMember]
public override IEnumerable<Base> Children
{
get
{
foreach (var item in base.Children) yield return item;
if (ContentTypeElement != null) yield return ContentTypeElement;
if (SecurityContext != null) yield return SecurityContext;
if (ContentElement != null) yield return ContentElement;
if (DataElement != null) yield return DataElement;
}
}

[IgnoreDataMember]
public override IEnumerable<ElementValue> NamedChildren
{
get
{
foreach (var item in base.NamedChildren) yield return item;
if (ContentTypeElement != null) yield return new ElementValue("contentType", ContentTypeElement);
if (SecurityContext != null) yield return new ElementValue("securityContext", SecurityContext);
if (ContentElement != null) yield return new ElementValue("content", ContentElement);
if (DataElement != null) yield return new ElementValue("data", DataElement);
}
}

internal protected override bool TryGetValue(string key, out object value)
{
switch (key)
Expand Down
Loading

0 comments on commit 6d4b929

Please sign in to comment.