diff --git a/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml b/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
index 7e7a407b40..948479e98b 100644
--- a/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
+++ b/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
@@ -239,6 +239,34 @@
lib/net8.0/Hl7.Fhir.Base.dll
true
+
+ CP0002
+ M:Hl7.Fhir.Model.Attachment.get_UrlElement
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0002
+ M:Hl7.Fhir.Model.Base.AsReadOnlyDictionary
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0002
+ M:Hl7.Fhir.Model.Base.get_Children
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0002
+ M:Hl7.Fhir.Model.Base.get_NamedChildren
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
CP0002
M:Hl7.Fhir.Model.Parameters.get_Item(System.String)
@@ -568,6 +596,405 @@
lib/net8.0/Hl7.Fhir.Base.dll
true
+
+ CP0008
+ T:Hl7.Fhir.Model.Attachment
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.BackboneElement
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.BackboneType
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Base
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Base64Binary
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Binary
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Bundle
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Bundle.EntryComponent
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Bundle.LinkComponent
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Bundle.RequestComponent
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Bundle.ResponseComponent
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Bundle.SearchComponent
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Canonical
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Code
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Code`1
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.CodeableConcept
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.CodeableReference
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Coding
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.ContactDetail
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.ContactPoint
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.DataType
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Date
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.DomainResource
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Element
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Extension
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.FhirBoolean
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.FhirDateTime
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.FhirDecimal
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.FhirString
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.FhirUri
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.FhirUrl
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Id
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Identifier
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Instant
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Integer
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Integer64
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Markdown
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Meta
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Narrative
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Oid
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.OperationOutcome
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.OperationOutcome.IssueComponent
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Parameters
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Parameters.ParameterComponent
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Period
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.PositiveInt
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.PrimitiveType
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Quantity
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Range
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Resource
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.ResourceReference
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Signature
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Time
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.UnsignedInt
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.UsageContext
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.Uuid
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
+
+ CP0008
+ T:Hl7.Fhir.Model.XHtml
+ lib/net8.0/Hl7.Fhir.Base.dll
+ lib/net8.0/Hl7.Fhir.Base.dll
+ true
+
CP0008
T:Hl7.Fhir.Serialization.BaseTypedElement
diff --git a/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs b/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs
index 9ad3073af2..8209c3ff88 100644
--- a/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs
+++ b/src/Hl7.Fhir.Base/ElementModel/NewPocoBuilder.cs
@@ -40,7 +40,7 @@ public Base BuildFrom(ITypedElement source)
private Base readFromElement(ITypedElement node, ClassMapping classMapping)
{
- IDictionary newInstance = buildNewInstance(classMapping);
+ var newInstance = buildNewInstance(classMapping);
// Capture the instance type if this is a dynamic type.
if(newInstance is IDynamicType dt)
@@ -79,7 +79,6 @@ private Base readFromElement(ITypedElement node, ClassMapping classMapping)
var childClassMapping = classMappingForElement(child, propertyMapping);
var convertedValue = readFromElement(child, childClassMapping);
-
// In case the convertedValue does not agree with the actual POCO type of the property, this
// method will throw an InvalidCastException. Later, we could salvage
// the data we have so far, and put it in an annotation.
@@ -87,7 +86,7 @@ private Base readFromElement(ITypedElement node, ClassMapping classMapping)
setOrAddProperty(child, newInstance, convertedValue, propertyMapping);
}
- return (Base)newInstance;
+ return newInstance;
}
private static void raiseFormatError(string message, string location)
@@ -95,14 +94,13 @@ private static void raiseFormatError(string message, string location)
throw Error.Format("While building a POCO: " + message, location);
}
- private static IDictionary buildNewInstance(ClassMapping mapping)
+ private static Base buildNewInstance(ClassMapping mapping)
{
- return mapping.Factory() switch
- {
- IDictionary b => b,
- _ => throw Error.InvalidOperation($"Class Factory for '{mapping.Name}' did not return a dictionary, which is required for " +
- $"building up POCO's dynamically.")
- };
+ if (mapping.Factory() is Base b) return b;
+
+ throw Error.InvalidOperation($"Class Factory for '{mapping.Name}' did not return a " +
+ $"Base, which is required for " +
+ $"building up POCO's dynamically.");
}
private IList buildNewList(PropertyMapping? propertyMapping, Type elementType)
@@ -118,7 +116,7 @@ private IList buildNewList(PropertyMapping? propertyMapping, Type elementType)
}
var propertyClassMapping = getClassMapping(propertyMapping.ImplementingType);
- return propertyClassMapping?.ListFactory() ?? new List();
+ return propertyClassMapping.ListFactory() ?? new List();
}
private ClassMapping classMappingForElement(ITypedElement node, PropertyMapping? propertyMapping)
@@ -212,7 +210,7 @@ private ClassMapping getClassMapping(Type t) =>
private ClassMapping getClassMapping() => getClassMapping(typeof(T));
- private void setOrAddProperty(ITypedElement node, IDictionary target,
+ private void setOrAddProperty(ITypedElement node, Base target,
Base convertedValue, PropertyMapping? propertyMapping)
{
// If this element *could* be repeating (either we don't know the definition, or it really is defined
@@ -291,7 +289,7 @@ private void setOrAddProperty(ITypedElement node, IDictionary ta
///
/// Convert the value of a typed element to a value that can be set on a POCO property.
///
- private object convertTypedElementValue(object value, string? instanceType)
+ private static object convertTypedElementValue(object value, string? instanceType)
{
return value switch
{
diff --git a/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs b/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs
index 11de6c464c..4f5dcaa8c3 100644
--- a/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs
+++ b/src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs
@@ -75,9 +75,9 @@ private Type determineInstanceType(PropertyMapping definition)
};
}
- public IElementDefinitionSummary Definition { get; private set; }
+ public IElementDefinitionSummary Definition { get; }
- public string ShortPath { get; private set; }
+ public string ShortPath { get; }
///
/// Elements from the IReadOnlyDictionary can be of type , IEnumerable<Base> or string.
@@ -107,15 +107,13 @@ public IEnumerable Children(string name)
{
if (Current is null) return Enumerable.Empty();
- var rod = Current.AsReadOnlyDictionary();
-
if (name is null)
{
- return rod.SelectMany(kvp
+ return Current.GetElementPairs().SelectMany(kvp
=> createChildNodes(kvp.Key, kvp.Value));
}
- rod.TryGetValue(name, out var dictValue);
+ Current.TryGetValue(name, out var dictValue);
return createChildNodes(name, dictValue);
IEnumerable createChildNodes(string childName, object value)
@@ -185,18 +183,13 @@ public object Value
{
get
{
- if (Current is PrimitiveType p && p.ObjectValue != null)
- {
- if (p.ObjectValue != _lastCachedValue)
- {
- _value = ToITypedElementValue();
- _lastCachedValue = p.ObjectValue;
- }
-
- return _value;
- }
- else
- return null;
+ if (Current is not PrimitiveType { ObjectValue: not null } p) return null;
+
+ if (p.ObjectValue == _lastCachedValue) return _value;
+
+ _value = ToITypedElementValue();
+ _lastCachedValue = p.ObjectValue;
+ return _value;
}
}
diff --git a/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs b/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs
index 5c55ebe274..8cbd87fc57 100644
--- a/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs
+++ b/src/Hl7.Fhir.Base/Model/Base.Dictionary.cs
@@ -7,87 +7,43 @@
namespace Hl7.Fhir.Model;
-public abstract partial class Base: IReadOnlyDictionary, IDictionary
+public class BaseDictionary(Base wrapped) : IReadOnlyDictionary
{
- private object get(string key) =>
- this.TryGetValue(key, out var value)
- ? value
- : throw new KeyNotFoundException($"Element '{key}' is not a known FHIR element or has no value.");
-
- public IReadOnlyDictionary AsReadOnlyDictionary() => this;
- public IDictionary AsDictionary() => this;
+ private static object wrap(object value) =>
+ value switch
+ {
+ Base b => new BaseDictionary(b),
+ _ => value
+ };
#region IReadOnlyDictionary
- IEnumerable IReadOnlyDictionary.Keys => GetElementPairs().Select(kvp => kvp.Key);
- IEnumerable