Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed IBaseElementNavigator<T> #2920

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
70 changes: 0 additions & 70 deletions src/Hl7.Fhir.Base/ElementModel/IBaseElementNavigator.cs

This file was deleted.

45 changes: 44 additions & 1 deletion src/Hl7.Fhir.Base/ElementModel/ITypedElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Hl7.Fhir.Specification;
using System.Collections.Generic;

#nullable enable

Expand All @@ -22,10 +23,52 @@ namespace Hl7.Fhir.ElementModel
/// </remarks>

#pragma warning disable CS0618 // Type or member is obsolete
public interface ITypedElement : IBaseElementNavigator<ITypedElement>
public interface ITypedElement
#pragma warning restore CS0618 // Type or member is obsolete
{
/// <summary>
/// Enumerate the child nodes present in the source representation (if any)
/// </summary>
/// <param name="name">Return only the children with the given name.</param>
/// <returns></returns>
IEnumerable<ITypedElement> Children(string? name = null);

/// <summary>
/// Name of the node, e.g. "active", "value".
/// </summary>
string Name { get; }

/// <summary>
/// Type of the node. If a FHIR type, this is just a simple string, otherwise a StructureDefinition url for a type defined as a logical model.
/// </summary>
string? InstanceType { get; }

/// <summary>
/// The value of the node (if it represents a primitive FHIR value)
/// </summary>
/// <remarks>
/// FHIR primitives are mapped to underlying C# types as follows:
///
/// instant Hl7.Fhir.ElementModel.Types.DateTime
/// time Hl7.Fhir.ElementModel.Types.Time
/// date Hl7.Fhir.ElementModel.Types.Date
/// dateTime Hl7.Fhir.ElementModel.Types.DateTime
/// decimal decimal
/// boolean bool
/// integer int
/// unsignedInt int
/// positiveInt int
/// long/integer64 long (name will be finalized in R5)
/// string string
/// code string
/// id string
/// uri, oid, uuid,
/// canonical, url string
/// markdown string
/// base64Binary string (uuencoded)
/// xhtml string
/// </remarks>
object? Value { get; }

/// <summary>
/// An indication of the location of this node within the data represented by the <c>ITypedElement</c>.
Expand Down
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/ElementModel/TypedElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static ITypedElement ToTypedElement(this Base @base, ModelInspector model
/// of the equation.</param>
/// <returns><c>true</c> when the ITypedElements are equal, <c>false</c> otherwise.</returns>
#pragma warning disable CS0618 // Type or member is obsolete
public static bool IsExactlyEqualTo<T>(this T? left, T? right, bool ignoreOrder = false) where T : IBaseElementNavigator<T>
public static bool IsExactlyEqualTo(this ITypedElement? left, ITypedElement? right, bool ignoreOrder = false)
#pragma warning restore CS0618 // Type or member is obsolete
{
if (left == null && right == null) return true;
Expand Down Expand Up @@ -102,7 +102,7 @@ public static bool ValueEquality<T1, T2>(T1? val1, T2? val2)
/// <param name="pattern"></param>
/// <returns><c>true</c> when <paramref name="value"/> matches the <paramref name="pattern"/>, <c>false</c> otherwise.</returns>
#pragma warning disable CS0618 // Type or member is obsolete
public static bool Matches<T>(this T value, T pattern) where T : IBaseElementNavigator<T>
public static bool Matches(this ITypedElement value, ITypedElement pattern)
#pragma warning restore CS0618 // Type or member is obsolete
{
if (value == null && pattern == null) return true;
Expand Down
22 changes: 11 additions & 11 deletions src/Hl7.Fhir.Base/ElementModel/TypedElementParseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public static class TypedElementParseExtensions
/// <inheritdoc cref="ParseBindable"/>
[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static Element? ParseBindableInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
public static Element? ParseBindableInternal(this ITypedElement instance)
{
return instance.InstanceType switch
{
FhirTypeConstants.CODE => instance.ParsePrimitiveInternal<Code, T>(),
FhirTypeConstants.STRING => new Code(instance.ParsePrimitiveInternal<FhirString, T>().Value),
FhirTypeConstants.URI => new Code(instance.ParsePrimitiveInternal<FhirUri, T>().Value),
FhirTypeConstants.CODE => instance.ParsePrimitiveInternal<Code>(),
FhirTypeConstants.STRING => new Code(instance.ParsePrimitiveInternal<FhirString>().Value),
FhirTypeConstants.URI => new Code(instance.ParsePrimitiveInternal<FhirUri>().Value),
FhirTypeConstants.CODING => instance.ParseCodingInternal(),
FhirTypeConstants.CODEABLE_CONCEPT => instance.ParseCodeableConceptInternal(),
FhirTypeConstants.QUANTITY => parseQuantity(),
Expand Down Expand Up @@ -90,7 +90,7 @@ public static Quantity ParseQuantity(this ITypedElement instance)

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static Quantity ParseQuantityInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
public static Quantity ParseQuantityInternal(this ITypedElement instance)
{
var newQuantity = new Quantity
{
Expand All @@ -111,12 +111,12 @@ public static Quantity ParseQuantityInternal<T>(this IBaseElementNavigator<T> in
#region ParsePrimitive
public static T ParsePrimitive<T>(this ITypedElement instance) where T : PrimitiveType, new()
#pragma warning disable CS0618 // Type or member is obsolete
=> ParsePrimitiveInternal<T, ITypedElement>(instance);
=> ParsePrimitiveInternal<T>(instance);
#pragma warning restore CS0618 // Type or member is obsolete

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static T ParsePrimitiveInternal<T, U>(this IBaseElementNavigator<U> instance) where T : PrimitiveType, new() where U : IBaseElementNavigator<U>
public static T ParsePrimitiveInternal<T>(this ITypedElement instance) where T : PrimitiveType, new()
=> new() { ObjectValue = instance.Value };

#endregion
Expand All @@ -130,7 +130,7 @@ public static Coding ParseCoding(this ITypedElement instance)

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static Coding ParseCodingInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
public static Coding ParseCodingInternal(this ITypedElement instance)
{
return new Coding()
{
Expand All @@ -151,7 +151,7 @@ public static ResourceReference ParseResourceReference(this ITypedElement instan

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static ResourceReference ParseResourceReferenceInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
public static ResourceReference ParseResourceReferenceInternal(this ITypedElement instance)
{
return new ResourceReference()
{
Expand All @@ -169,7 +169,7 @@ public static CodeableConcept ParseCodeableConcept(this ITypedElement instance)

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static CodeableConcept ParseCodeableConceptInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
public static CodeableConcept ParseCodeableConceptInternal(this ITypedElement instance)
{
return new CodeableConcept()
{
Expand All @@ -181,7 +181,7 @@ public static CodeableConcept ParseCodeableConceptInternal<T>(this IBaseElementN
#endregion

#pragma warning disable CS0618 // Type or member is obsolete
public static string? GetString<T>(this IEnumerable<T> instance) where T : IBaseElementNavigator<T>
public static string? GetString(this IEnumerable<ITypedElement> instance)
#pragma warning restore CS0618 // Type or member is obsolete
=> instance.SingleOrDefault()?.Value as string;
}
Expand Down
22 changes: 6 additions & 16 deletions src/Hl7.Fhir.Base/Model/Base.TypedElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ public interface IScopedNode : ITypedElement, IShortPathGenerator
/// <summary>
/// The parent node of this node, or null if this is the root node.
/// </summary>
IScopedNode? Parent { get; }

// /// <summary>
// /// An indication of the location of this node within the data represented by the <c>ITypedElement</c>.
// /// </summary>
// /// <remarks>The format of the location is the dotted name of the property, including indices to make
// /// sure repeated occurrences of an element can be distinguished. It needs to be sufficiently precise to aid
// /// the user in locating issues in the data.</remarks>
// string Location { get; }
IScopedNode? Parent { get; }
}

internal record ScopeInformation(IScopedNode? Parent, string Name, int? Index);
Expand All @@ -65,7 +57,7 @@ internal Base WithScopeInfo(ScopeInformation info)
return this;
}

IEnumerable<ITypedElement> IBaseElementNavigator<ITypedElement>.Children(string? name) =>
IEnumerable<ITypedElement> ITypedElement.Children(string? name) =>
this.GetElementPairs()
.Where(ep => (name == null || name == ep.Key))
.SelectMany<KeyValuePair<string, object>, Base>(ep =>
Expand All @@ -82,15 +74,15 @@ IEnumerable<ITypedElement> IBaseElementNavigator<ITypedElement>.Children(string?

IScopedNode? IScopedNode.Parent => ScopeInfo.Parent;

string IBaseElementNavigator<ITypedElement>.Name => ScopeInfo.Name;
string ITypedElement.Name => ScopeInfo.Name;

// TODO:
// Als wij een BackboneElement zijn, dan is onze naam niet this.TypeName maar "BackboneElement" of
// "Element", afhankelijk van waar hij in de .net inheritance hierarchie zit.
// HEt moet "code" zijn als dit een "Code<T>" is. Dat zijn geloof ik de afwijkingen.
// Wellioht is er ook nog iets met de directe properties "Extension.url" en "Element.id" die van een
// system type zijn ipv een FHIR type.
string? IBaseElementNavigator<ITypedElement>.InstanceType =>
string? ITypedElement.InstanceType =>
((IStructureDefinitionSummary)
ModelInspector
.ForType(this.GetType())
Expand Down Expand Up @@ -127,7 +119,7 @@ IEnumerable<ITypedElement> IBaseElementNavigator<ITypedElement>.Children(string?
}
}

object? IBaseElementNavigator<ITypedElement>.Value
object? ITypedElement.Value
{
get
{
Expand Down Expand Up @@ -168,9 +160,7 @@ IEnumerable<ITypedElement> IBaseElementNavigator<ITypedElement>.Children(string?

string? IResourceTypeSupplier.ResourceType =>
this is Resource
#pragma warning disable CS0618 // Type or member is obsolete
? ((IBaseElementNavigator<ITypedElement>)this).InstanceType
#pragma warning restore CS0618 // Type or member is obsolete
? ((ITypedElement)this).InstanceType
: null;
}

Expand Down