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

3061 Add nullability #3062

Merged
merged 7 commits into from
Feb 26, 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
  •  
  •  
  •  
1 change: 1 addition & 0 deletions src/Hl7.Fhir.Base/Hl7.Fhir.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Title>Firely's HL7 FHIR SDK Base Class Library</Title>
<Description>Firely's HL7 FHIR SDK Base Class Library. Is a dependency for the FHIR release-specific NuGet packages and is usually not directly referenced.</Description>
<PackageTags>HL7;FHIR;Firely;SDK;BCL</PackageTags>
<RootNamespace>Hl7.Fhir</RootNamespace>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
Expand Down
14 changes: 9 additions & 5 deletions src/Hl7.Fhir.Base/Model/Base.Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/*
* Copyright (c) 2025, Firely (info@fire.ly) and contributors
* See the file CONTRIBUTORS for details.
*
* This file is licensed under the BSD 3-Clause license
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE
*/

#nullable enable
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Rest;
using Hl7.Fhir.Utility;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

Expand Down
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/Model/Bundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public Uri? Alternate

private Uri? getLink(string rel)
{
if (Link is null) return null;
if (!Link.Any()) return null;

var entry = Link.FirstOrDefault(e => rel.Equals(e.Relation, StringComparison.OrdinalIgnoreCase));

return entry != null ? new Uri(entry.Url, UriKind.RelativeOrAbsolute) : null;
return entry?.Url != null ? new Uri(entry.Url, UriKind.RelativeOrAbsolute) : null;
}

private void setLink(string rel, Uri? uri)
Expand Down
10 changes: 6 additions & 4 deletions src/Hl7.Fhir.Base/Model/Canonical.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,25 @@ public static Canonical ForCoreType(string typename)
/// <summary>
/// The version string of the canonical (if present).
/// </summary>
public string? Version => splitCanonical(Value).version;
public string? Version => Value is null ? null : splitCanonical(Value).version;

/// <summary>
/// Optional anchor at the end of the canonical, without the '#' prefix.
/// </summary>
public string? Fragment => splitCanonical(Value).fragment;
public string? Fragment => Value is null ? null : splitCanonical(Value).fragment;

/// <summary>
/// The uri part of the canonical, which is the canonical without the version indication.
/// </summary>
public string? Uri => splitCanonical(Value).url;
public string? Uri => Value is null ? null : splitCanonical(Value).url;

/// <summary>
/// Converts the canonical to a <see cref="System.Uri" />.
/// </summary>
/// <returns></returns>
public Uri ToUri() => new(Value, UriKind.RelativeOrAbsolute);
public Uri ToUri() => new(
Value ?? throw new InvalidOperationException("Cannot turn a canonical without a value into a Uri"),
UriKind.RelativeOrAbsolute);

/// <summary>
/// Whether the canonical is a relative or an absolute uri.
Expand Down
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Base/Model/CodeableReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public P.Concept ToSystemConcept() =>
"and can therefore not be converted to a System Concept.");

internal P.Concept? ToSystemConceptInternal() =>
((P.IToSystemPrimitive)Concept)?.TryConvertToSystemType(out var result) == true ? (P.Concept)result : null;
((P.IToSystemPrimitive?)Concept)?.TryConvertToSystemType(out var result) == true ? (P.Concept)result : null;

/// <summary>
/// Converts the reference part of this CodeableReference to a <see cref="P.String" />.
Expand Down
Loading
Loading