diff --git a/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs b/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs
index 8209c3ff8..b6d83b4b8 100644
--- a/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs
+++ b/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs
@@ -54,9 +54,16 @@ private Base readFromElement(ITypedElement node, ClassMapping classMapping)
var objectValue = newInstance is DynamicPrimitive ?
value :
convertTypedElementValue(value, node.InstanceType);
- newInstance["value"] = objectValue;
- if (settings?.AllowUnrecognizedEnums == false && classMapping.EnumType is not null && objectValue is string enumLiteral)
+ if(newInstance is PrimitiveType pt)
+ pt.ObjectValue = objectValue;
+ else
+ raiseFormatError($"{node.Name} is a primitive of type {value.GetType()}, but the target POCO is a {newInstance.GetType()}, " +
+ $"which is not FHIR primitive.", node.Location);
+
+ if (settings?.AllowUnrecognizedEnums == false &&
+ classMapping.EnumType is not null &&
+ objectValue is string enumLiteral)
{
// Backwards-compatible check for enums. Although our POCOs accept strings rather
// than enum values, this check is still useful for catching typos in the data and may
diff --git a/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs b/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs
index e263074fe..e32b48d3b 100644
--- a/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs
+++ b/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs
@@ -36,7 +36,7 @@ internal PocoElementNode(ModelInspector inspector, Base root, string rootName =
InstanceType = ((IStructureDefinitionSummary)_myClassMapping).TypeName;
Definition = ElementDefinitionSummary.ForRoot(_myClassMapping, rootName ?? root.TypeName);
- Location = InstanceType;
+ Location = InstanceType!;
ShortPath = InstanceType;
}
@@ -49,9 +49,9 @@ private PocoElementNode(ModelInspector inspector, Base instance, PocoElementNode
var instanceType = definition.Choice != ChoiceType.None
? instance.GetType()
: determineInstanceType(definition);
- _myClassMapping = _inspector.FindOrImportClassMapping(instanceType);
+ _myClassMapping = _inspector.FindOrImportClassMapping(instanceType)!;
InstanceType = ((IStructureDefinitionSummary)_myClassMapping).TypeName;
- Definition = definition ?? throw Error.ArgumentNull(nameof(definition));
+ Definition = definition;
ExceptionHandler = parent.ExceptionHandler;
Location = location;
diff --git a/src/Hl7.Fhir.Base/Introspection/PropertyMapping.cs b/src/Hl7.Fhir.Base/Introspection/PropertyMapping.cs
index b0a7650d5..d922a469a 100644
--- a/src/Hl7.Fhir.Base/Introspection/PropertyMapping.cs
+++ b/src/Hl7.Fhir.Base/Introspection/PropertyMapping.cs
@@ -343,7 +343,8 @@ private ITypeSerializationInfo[] buildTypes()
}
else if (IsPrimitive)
{
- throw new NotSupportedException($"Encountered unexpected primitive type {Name} for ITypedElement.InstanceType.")
+ throw new NotSupportedException(
+ $"Encountered unexpected primitive type {Name} for ITypedElement.InstanceType.");
}
else
{
diff --git a/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs b/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs
index 8cbd87fc5..d8b024102 100644
--- a/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs
+++ b/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs
@@ -1,3 +1,5 @@
+#if NOT_USED
+
using System;
using System.Collections;
using System.Collections.Generic;
@@ -46,4 +48,6 @@ IEnumerator IEnumerable.GetEnumerator() =>
#endregion
-}
\ No newline at end of file
+}
+
+#endif
\ No newline at end of file
diff --git a/src/Hl7.Fhir.Base/Model/Base.Extensions.cs b/src/Hl7.Fhir.Base/Model/Base.Extensions.cs
index 261b45612..0a0a33965 100644
--- a/src/Hl7.Fhir.Base/Model/Base.Extensions.cs
+++ b/src/Hl7.Fhir.Base/Model/Base.Extensions.cs
@@ -18,11 +18,8 @@ public static IEnumerable Children(this Base instance)
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);
+ case ("id", FhirUri id):
+ yield return new FhirString(id.Value);
break;
case (_, IEnumerable list):
foreach (var item in list)
diff --git a/src/Hl7.Fhir.Base/Model/Base.TypedElement.cs b/src/Hl7.Fhir.Base/Model/Base.TypedElement.cs
index 3cba3661a..b1f61ff0b 100644
--- a/src/Hl7.Fhir.Base/Model/Base.TypedElement.cs
+++ b/src/Hl7.Fhir.Base/Model/Base.TypedElement.cs
@@ -93,17 +93,13 @@ IEnumerable ITypedElement.Children(string? name) =>
this.GetElementPairs()
.Where(ep => (name == null || name == ep.Key))
.SelectMany, Base>(ep =>
- (ep.Key, ep.Value) switch
+ ep.Value switch
{
- (_, Base b) => (IEnumerable) [b.WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
- (_, IEnumerable list) => list.Select((item, idx) =>
+ Base b => (IEnumerable) [b.WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
+ IEnumerable list => list.Select((item, idx) =>
item.WithScopeInfo(new ScopeInformation(this, ep.Key, idx))),
- ("url", string s) when this is Extension =>
- [new FhirUri(s).WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
- ("id", string s) when this is Element =>
- [new FhirString(s).WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
- ("value", _) => [],
- _ => throw new InvalidOperationException("Unexpected system primitive in child list")
+ _ => throw new InvalidOperationException($"Key '{ep.Key}' has a value with " +
+ $"unexpected type '{ep.Value.GetType()}'.")
}
);
@@ -218,14 +214,12 @@ bool IScopedNode.TryResolveContainedEntry(string id, [NotNullWhen(true)] out ISc
IEnumerable IScopedNode.Children(string? name) => this.GetElementPairs()
.Where(ep => (name == null || name == ep.Key))
.SelectMany, Base>(ep =>
- (ep.Key, ep.Value) switch
+ ep.Value switch
{
- (_, Base b) => (IEnumerable)[b.WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
- (_, IEnumerable list) => list.Select((item, idx) => item.WithScopeInfo(new ScopeInformation(this, ep.Key, idx))),
- ("url", string s) when this is Extension => [new FhirUri(s).WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
- ("id", string s) when this is Element => [new FhirString(s).WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
- ("value", _) => [],
- _ => throw new InvalidOperationException("Unexpected system primitive in child list")
+ Base b => (IEnumerable)[b.WithScopeInfo(new ScopeInformation(this, ep.Key, null))],
+ IEnumerable list => list.Select((item, idx) => item.WithScopeInfo(new ScopeInformation(this, ep.Key, idx))),
+ _ => throw new InvalidOperationException($"Key '{ep.Key}' has a value with " +
+ $"unexpected type '{ep.Value.GetType()}'.")
}
);
diff --git a/src/Hl7.Fhir.Base/Model/Base.cs b/src/Hl7.Fhir.Base/Model/Base.cs
index 4a4873687..8e366b433 100644
--- a/src/Hl7.Fhir.Base/Model/Base.cs
+++ b/src/Hl7.Fhir.Base/Model/Base.cs
@@ -30,15 +30,12 @@ POSSIBILITY OF SUCH DAMAGE.
#nullable enable
using Hl7.Fhir.ElementModel;
-using Hl7.Fhir.Introspection;
using Hl7.Fhir.Utility;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Runtime.Serialization;
using System.Threading;
namespace Hl7.Fhir.Model;
@@ -51,7 +48,6 @@ public abstract partial class Base : IDeepCopyable, IDeepComparable,
///
public virtual string TypeName => GetType().Name;
-
private Dictionary? _overflow = null;
///
@@ -71,11 +67,11 @@ public abstract partial class Base : IDeepCopyable, IDeepComparable,
public IEnumerable