Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
434 changes: 84 additions & 350 deletions src/Hl7.Fhir.Base/CompatibilitySuppressions.xml

Large diffs are not rendered by default.

123 changes: 0 additions & 123 deletions src/Hl7.Fhir.Base/ElementModel/ElementNodeExtensions.cs

This file was deleted.

81 changes: 40 additions & 41 deletions src/Hl7.Fhir.Base/ElementModel/ISourceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,51 @@

using System.Collections.Generic;

namespace Hl7.Fhir.ElementModel
namespace Hl7.Fhir.ElementModel;

/// <summary>
/// A node within a tree of FHIR data.
/// </summary>
/// <remarks>
/// <para>This interface is typically implemented by a parser for one of the low-level serialization formats for FHIR, i.e.
/// FHIR xml/json/rdf or v3 XML. The interface does not depend on the availability of FHIR metadata and definitions
/// (in contrast to <see cref="ITypedElement" />), so the names of the nodes will have their type suffixes (for choice types)
/// and all primitives values are represented as strings, instead of native objects.</para>
/// <para>Implementations of this interface that want to report errors while parsing should only do so on the
/// <see cref="Children(string)"/> function and <see cref="Text"/> getter.</para>
/// </remarks>
public interface ISourceNode
{
/// <summary>
/// A node within a tree of FHIR data.
/// Gets the name of the node, e.g. "active", "valueQuantity".
/// </summary>
/// <remarks>
/// <para>This interface is typically implemented by a parser for one of the low-level serialization formats for FHIR, i.e.
/// FHIR xml/json/rdf or v3 XML. The interface does not depend on the availability of FHIR metadata and definitions
/// (in contrast to <see cref="ITypedElement" />), so the names of the nodes will have their type suffixes (for choice types)
/// and all primitives values are represented as strings, instead of native objects.</para>
/// <para>Implementations of this interface that want to report errors while parsing should only do so on the
/// <see cref="Children(string)"/> function and <see cref="Text"/> getter.</para>
/// <remarks>Since the node has no type information, choice elements are represented as their
/// name on the wire, possibly including the type suffix for choice elements.
/// </remarks>
public interface ISourceNode
{
/// <summary>
/// Gets the name of the node, e.g. "active", "valueQuantity".
/// </summary>
/// <remarks>Since the node has no type information, choice elements are represented as their
/// name on the wire, possibly including the type suffix for choice elements.
/// </remarks>
string Name { get; }
string Name { get; }

/// <summary>
/// Gets the text of the primitive value of the node
/// </summary>
/// <value>Returns the raw textual value as represented in the serialization, or null if there is no value in this node.</value>
string Text { get; }
/// <summary>
/// Gets the text of the primitive value of the node
/// </summary>
/// <value>Returns the raw textual value as represented in the serialization, or null if there is no value in this node.</value>
string Text { get; }

/// <summary>
/// Gets the location of this node within the tree of data.
/// </summary>
/// <value>A string of dot-separated names representing the path to the node within the tree, including indices
/// to distinguish repeated occurences of an element.</value>
string Location { get; }
/// <summary>
/// Gets the location of this node within the tree of data.
/// </summary>
/// <value>A string of dot-separated names representing the path to the node within the tree, including indices
/// to distinguish repeated occurences of an element.</value>
string Location { get; }

/// <summary>
/// Enumerates the direct child nodes of the current node (if any).
/// </summary>
/// <param name="name">Optional. The name filter for the children. Can be omitted to not filter by name.</param>
/// <returns>The children of the node matching the given filter, or all children if no filter was specified.
/// If no children match the given filter, the function returns an empty enumerable.</returns>
/// <remarks>
/// <para>If the <paramref name="name"/>parameter ends in an asterix ('*'),
/// the function will return the children of which the name starts with the given name.</para>
/// <para>Repeating elements will always be returned consecutively.</para></remarks>
IEnumerable<ISourceNode> Children(string name = null);
}
/// <summary>
/// Enumerates the direct child nodes of the current node (if any).
/// </summary>
/// <param name="name">Optional. The name filter for the children. Can be omitted to not filter by name.</param>
/// <returns>The children of the node matching the given filter, or all children if no filter was specified.
/// If no children match the given filter, the function returns an empty enumerable.</returns>
/// <remarks>
/// <para>If the <paramref name="name"/>parameter ends in an asterix ('*'),
/// the function will return the children of which the name starts with the given name.</para>
/// <para>Repeating elements will always be returned consecutively.</para></remarks>
IEnumerable<ISourceNode> Children(string name = null);
}
36 changes: 0 additions & 36 deletions src/Hl7.Fhir.Base/ElementModel/PocoBuilderExtensions.cs

This file was deleted.

13 changes: 13 additions & 0 deletions src/Hl7.Fhir.Base/ElementModel/PocoNodeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Utility;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -288,4 +289,16 @@ internal static IEnumerable<PocoNode> Where<T>(this PocoListNode pln, Func<T, bo
}

internal static ModelInspector? FindInspector(this PocoNode node) => ((IAnnotated)node).Annotation<ModelInspector>() ?? node.Parent?.SingleOrDefault()?.FindInspector();

internal static string SerializeToString(this PocoNode pn, bool pretty)
{
var serializer = new BaseFhirXmlSerializer(pn.FindInspector() ?? ModelInspector.ForType(pn.Poco.GetType()));

// If we are serializing a subtree of a resource, then if the current node is a datatype or a nested resource,
// we need to pick a name for this root element.
var pickElementName = pn.Poco is not Resource || pn.Parent is not null;
var rootName = pickElementName ? pn.Name : null;

return serializer.SerializeToString(pn.Poco, pretty, rootName: rootName);
}
}
Loading