Skip to content

Commit

Permalink
Better documentation of the side-effect of ValidateObjectValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutkramer committed Feb 26, 2025
1 parent c96ed23 commit ad3f0ff
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Hl7.Fhir.Base/Model/Base64Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public override object? ObjectValue
[NonSerialized] // To prevent binary serialization from serializing this field
private byte[]? _parsedValue = null;

/// <summary>
/// Validates the JsonValue and updates the internal cached byte[] Value, releasing
/// the data in JsonValue to save memory.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context)
{
if (_parsedValue is not null || base.ObjectValue is null) return null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Canonical.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public void Deconstruct(out string? uri, out string? version, out string? fragme
/// <param name="value"></param>
public static implicit operator string?(Canonical? value) => value?.Value;

/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Code.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Value is not null
? new P.Code(system: null, code: Value, display: null, version: null)
: null;

/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/CodeOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public override object? ObjectValue
}
}

/// <summary>
/// Validates the JsonValue and updates the internal cached enum Value.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context)
{
if (_parsedValue is not null || base.ObjectValue is null) return null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Date.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public Date(int year) : this(string.Format(System.Globalization.CultureInfo.Inva
[NonSerialized] // To prevent binary serialization from serializing this field
private P.Date? _parsedValue = null;

/// <summary>
/// Validates the JsonValue and updates the internal cached Date value.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context)
{
if (_parsedValue is not null || base.ObjectValue is null) return null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/FhirBoolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Hl7.Fhir.Model;

public partial class FhirBoolean
{
/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/FhirDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public FhirDateTime(int year)
[NonSerialized] // To prevent binary serialization from serializing this field
private P.DateTime? _parsedValue = null;

/// <summary>
/// Validates the JsonValue and updates the internal cached DateTime value.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context)
{
if (_parsedValue is not null || base.ObjectValue is null) return null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/FhirDecimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Hl7.Fhir.Model;

public partial class FhirDecimal
{
/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/FhirString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Hl7.Fhir.Model;

public partial class FhirString : ICoded
{
/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/FhirUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public FhirUri(Uri uri)
Value = uri.OriginalString;
}

/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/FhirUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public FhirUrl(Uri uri)
Value = uri.OriginalString;
}

/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Id.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace Hl7.Fhir.Model;

public partial class Id
{
/// <summary>
/// Validates the JsonValue and updates the internal cached Date value.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Instant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public static Instant FromDateTimeUtc(int year, int month, int day,
[NonSerialized] // To prevent binary serialization from serializing this field
private P.DateTime? _parsedValue = null;

/// <summary>
/// Validates the JsonValue and updates the internal cached CQL DateTime value.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context)
{
if (_parsedValue is not null || base.ObjectValue is null) return null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Integer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Hl7.Fhir.Model;

public partial class Integer
{
/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Integer64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public long? Value
[NonSerialized] // To prevent binary serialization from serializing this field
private long? _parsedValue = null;

/// <summary>
/// Validates the JsonValue and updates the internal cached long value.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context)
{
if (_parsedValue is not null || base.ObjectValue is null) return null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Markdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Hl7.Fhir.Model;

public partial class Markdown
{
/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
1 change: 1 addition & 0 deletions src/Hl7.Fhir.Base/Model/Oid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Hl7.Fhir.Model;

public partial class Oid
{
/// Validates the JsonValue.
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
1 change: 1 addition & 0 deletions src/Hl7.Fhir.Base/Model/PositiveInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Hl7.Fhir.Model;

public partial class PositiveInt
{
/// Validates the JsonValue.
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
4 changes: 4 additions & 0 deletions src/Hl7.Fhir.Base/Model/PrimitiveType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext vali
protected virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext) =>
ValidateObjectValue(validationContext) is { } result ? [result.AsResult(validationContext)] : [];

/// <summary>
/// Validates the JsonValue. Some subclasses will also, as a side-effect, update
/// their internal cache if parsing and validating is expensive.
/// </summary>
protected internal abstract CodedValidationException? ValidateObjectValue(ValidationContext? validationContext);

public bool HasValidValue() => ValidateObjectValue(null) is null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public Time(int hour, int minute, int second) : this(string.Format(CultureInfo.I
[NonSerialized] // To prevent binary serialization from serializing this field
private P.Time? _parsedValue = null;

/// <summary>
/// Validates the JsonValue and updates the internal cached Time value.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context)
{
if (_parsedValue is not null || base.ObjectValue is null) return null;
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/UnsignedInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Hl7.Fhir.Model;

public partial class UnsignedInt
{
/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/Uuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static Uuid Generate()
/// </summary>
public FhirUri AsUri() => new(Value);

/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Model/XHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace Hl7.Fhir.Model;
/// </summary>
public partial class XHtml
{
/// <summary>
/// Validates the JsonValue.
/// </summary>
protected internal override COVE? ValidateObjectValue(ValidationContext? context) =>
ObjectValue switch
{
Expand Down

0 comments on commit ad3f0ff

Please sign in to comment.