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

Allow the model to store invalid data and give detailed exceptions about it #3079

Merged
merged 17 commits into from
Mar 25, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/ElementModel/ElementNodeComparator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public static TreeComparisonResult IsEqualTo(this ITypedElement expected, ITyped
foreach (var exp in childrenExp)
{
if (!childrenActual.MoveNext())
TreeComparisonResult.Fail(actual.Location, $"number of children was different");
return TreeComparisonResult.Fail(actual.Location, $"number of children was different");

var result = exp.IsEqualTo(childrenActual.Current);
if (!result.Success)
return result;
}
if (childrenActual.MoveNext())
TreeComparisonResult.Fail(actual.Location, $"number of children was different");
return TreeComparisonResult.Fail(actual.Location, $"number of children was different");

return TreeComparisonResult.OK;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Hl7.Fhir.Base/Model/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;

namespace Hl7.Fhir.Model;
Expand All @@ -46,8 +47,10 @@ public abstract partial class Base : IAnnotatable, INotifyPropertyChanged
/// FHIR Type Name
/// </summary>
public virtual string TypeName => GetType().Name;

private Dictionary<string, object>? _overflow = null;

protected bool HasOverflow => _overflow is not null && _overflow.Any();

/// <summary>
/// A dictionary containing all elements that are not explicitly defined in the class.
Expand Down Expand Up @@ -130,7 +133,7 @@ public object this[string key]
/// <returns><c>true</c> if the given value was set in the POCO or present in the overflow dictionary, <c>false</c> otherwise.
/// For lists, this means they should not be empty.</returns>
public virtual bool TryGetValue(string key, [NotNullWhen(true)] out object? value) =>
Overflow.TryGetValue(key, out value) && (value is not IReadOnlyList<Base> list || list.Count > 0);
Overflow.TryGetValue(key, out value);

/// <summary>
/// Enumerates all non-empty elements in the POCO and the overflow dictionary.
Expand Down
Loading