@@ -15,13 +15,9 @@ namespace Hl7.Fhir.Model;
1515/// A singular node in a POCO node tree. This node represents either a repeating or singular POCO instance.
1616/// </summary>
1717/// <param name="Name"></param>
18- public abstract record PocoNodeOrList ( string Name ) : IEnumerable < PocoNode >
18+ /// <param name="Parent"></param>
19+ public abstract record PocoNodeOrList ( string Name , PocoNode ? Parent ) : IEnumerable < PocoNode >
1920{
20- /// <summary>
21- /// The parent of this node. This is always a singular PocoNode. If the Parent field is set to a PocoListNode, this will construct and return the PocoNode at the specified index.
22- /// </summary>
23- public abstract PocoNode ? Parent { get ; }
24-
2521 public abstract IEnumerator < PocoNode > GetEnumerator ( ) ;
2622 IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
2723
@@ -36,20 +32,12 @@ public abstract record PocoNodeOrList(string Name) : IEnumerable<PocoNode>
3632/// A singular node in a POCO node tree. This node represents a single POCO instance.
3733/// </summary>
3834/// <param name="Poco"></param>
39- /// <param name="ParentNode "></param>
35+ /// <param name="Parent "></param>
4036/// <param name="Index">This Poco's index in a list, if it is contained in one</param>
4137/// <param name="Name"></param>
42- public partial record PocoNode ( Base Poco , PocoNodeOrList ? ParentNode , int ? Index , string ? Name )
43- : PocoNodeOrList ( Name ?? Poco . TypeName ) , ITypedElement , IShortPathGenerator , ISourceNode , IFhirValueProvider , IResourceTypeSupplier , IAnnotatable
38+ public partial record PocoNode ( Base Poco , PocoNode ? Parent , int ? Index , string ? Name )
39+ : PocoNodeOrList ( Name ?? Poco . TypeName , Parent ) , ITypedElement , IShortPathGenerator , ISourceNode , IFhirValueProvider , IResourceTypeSupplier , IAnnotatable
4440{
45- /// <inheritdoc />
46- public override PocoNode ? Parent => ParentNode switch
47- {
48- PocoListNode nodes => nodes [ Index ! . Value ] ,
49- PocoNode node => node ,
50- _ => null
51- } ;
52-
5341 /// <summary>
5442 /// Enumerates all children of this node. These can each either be singular or repeating PocoNodes.
5543 /// </summary>
@@ -83,8 +71,8 @@ private PocoNodeOrList nodeFor(string name, object value) =>
8371 {
8472 PrimitiveType primitive => new PrimitiveNode ( primitive , this , null , name ) ,
8573 Base b => new PocoNode ( b , this , null , name ) ,
86- IEnumerable < PrimitiveType > primitiveList => new PrimitiveListNode ( primitiveList . ToList ( ) , this , name ) ,
87- IEnumerable < Base > list => new PocoListNode ( list . ToList ( ) , this , name ) ,
74+ IReadOnlyList < PrimitiveType > primitiveList => new PrimitiveListNode ( primitiveList . ToList ( ) , this , name ) ,
75+ IReadOnlyList < Base > list => new PocoListNode ( list . ToList ( ) , this , name ) ,
8876 _ => throw new InvalidOperationException ( "Unexpected element in child list" )
8977 } ;
9078
@@ -153,11 +141,10 @@ IEnumerable<object> IAnnotated.Annotations(Type type)
153141/// A single node for a repeating element. Note that since a repeating element has a single parent, this cannot be used for grouping "separate" pocos that are not repeating in the specification.
154142/// </summary>
155143/// <param name="Pocos"></param>
156- /// <param name="ParentNode "></param>
144+ /// <param name="Parent "></param>
157145/// <param name="Name"></param>
158- public record PocoListNode ( IReadOnlyList < Base > Pocos , PocoNodeOrList ? ParentNode , string Name ) : PocoNodeOrList ( Name )
146+ public record PocoListNode ( IReadOnlyList < Base > Pocos , PocoNode ? Parent , string Name ) : PocoNodeOrList ( Name , Parent )
159147{
160148 public PocoNode this [ int index ] => new ( Pocos [ index ] , Parent , index , Name ) ;
161- public override PocoNode ? Parent => ParentNode as PocoNode ; // safe because FHIR knows no nested lists
162149 public override IEnumerator < PocoNode > GetEnumerator ( ) => Pocos . Select ( ( poco , index ) => new PocoNode ( poco , Parent , index , Name ) ) . GetEnumerator ( ) ;
163150}
0 commit comments