Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/move-to-netstandard-2.1' into mo…
Browse files Browse the repository at this point in the history
…ve-to-netstandard-2.1
  • Loading branch information
Kasdejong committed Oct 23, 2024
2 parents 45683a4 + 38fde6a commit 090d26a
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 68 deletions.
1 change: 0 additions & 1 deletion src/Hl7.Fhir.Base/Hl7.Fhir.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

Expand Down
13 changes: 5 additions & 8 deletions src/Hl7.Fhir.Base/Rest/EntryToHttpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Utility;
using System;
using System.Linq;
using System.Net.Http;

namespace Hl7.Fhir.Rest
Expand All @@ -36,16 +35,16 @@ public static HttpRequestMessage ToHttpRequestMessage(
var serialization = settings.PreferredFormat;

var uri = getRequestUrl(baseUrl, request.Url);

var message = new HttpRequestMessage(method, uri);

if (!(binaryEndpoint && settings.BinaryReceivePreference == BinaryTransferBehaviour.UseData))
{
message = settings.UseFormatParameter
message = settings.UseFormatParameter
? message.WithFormatParameter(serialization)
: message.WithAccept(serialization, fhirVersion, settings.PreferCompressedResponses);
}

message = setBody(message)
.WithDefaultAgent()
.WithPreconditions(request.IfMatch, request.IfNoneMatch, request.IfModifiedSince, request.IfNoneExist);
Expand Down Expand Up @@ -95,11 +94,9 @@ private static Uri getRequestUrl(Uri baseUrl, string requestUrl)
}


#if NETSTANDARD
private readonly static HttpMethod HTTP_PATCH = new("PATCH");
#else

private readonly static HttpMethod HTTP_PATCH = HttpMethod.Patch;
#endif


/// <summary>
/// Converts the <see cref="Bundle.HTTPVerb" /> (e.g. from a <see cref="Bundle.RequestComponent.Method"/>) to a <see cref="HttpMethod"/>. />
Expand Down
10 changes: 4 additions & 6 deletions src/Hl7.Fhir.Base/Serialization/BaseFhirJsonPocoDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/


#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
Expand Down Expand Up @@ -368,7 +367,7 @@ FhirJsonPocoDeserializerState state
// This is not a FHIR primitive, so we should not be dealing with these weird _name members.
if (propertyName[0] == '_')
state.Errors.Add(ERR.USE_OF_UNDERSCORE_ILLEGAL(ref reader, state.Path.GetInstancePath(), propertyMapping.Name, propertyName));

// Note that repeating simple elements (like Extension.url) do not currently exist in the FHIR serialization
if (propertyMapping.IsCollection)
{
Expand All @@ -380,8 +379,8 @@ FhirJsonPocoDeserializerState state
state.Errors.Add(ERR.DUPLICATE_ARRAY(ref reader, state.Path.GetInstancePath()));
}
result = deserializeNormalList(l, propertyValueMapping, ref reader, propertyMapping, state);
}
else
}
else
{
// if the property already has a value, its key must have been encountered before
if (existingValue is not null)
Expand Down Expand Up @@ -980,5 +979,4 @@ internal class FhirJsonPocoDeserializerState
}
}

#nullable restore
#endif
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#nullable enable

#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

using Hl7.Fhir.Introspection;
using Hl7.Fhir.Model;
using Hl7.Fhir.Specification;
Expand Down Expand Up @@ -331,5 +329,5 @@ protected virtual void SerializePrimitiveValue(object value, Utf8JsonWriter writ
}
}

#endif

#nullable restore
16 changes: 7 additions & 9 deletions src/Hl7.Fhir.Base/Serialization/FhirJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#nullable enable

#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

using Hl7.Fhir.Introspection;
using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
Expand Down Expand Up @@ -42,13 +40,13 @@ public FhirJsonConverterFactory(
internal void SetEnforcedErrors(IEnumerable<string> toEnforce)
{
Engine ??= createDefaultEngine();
Engine.IgnoreFilter = Engine.IgnoreFilter.And(toEnforce.ToPredicate().Negate());
Engine.IgnoreFilter = Engine.IgnoreFilter.And(toEnforce.ToPredicate().Negate());
}

internal void SetIgnoredErrors(IEnumerable<string> toIgnore)
{
Engine ??= createDefaultEngine();
Engine.IgnoreFilter = Engine.IgnoreFilter.Or(toIgnore.ToPredicate());
Engine.IgnoreFilter = Engine.IgnoreFilter.Or(toIgnore.ToPredicate());
}

internal void SetMode(DeserializerModes mode)
Expand All @@ -69,7 +67,7 @@ internal void SetMode(DeserializerModes mode)
Engine ??= createDefaultEngine();
return (JsonConverter?)Activator.CreateInstance(
typeof(FhirJsonConverter<>).MakeGenericType(typeToConvert), BindingFlags.NonPublic | BindingFlags.Instance, null,
[ Engine ], null, null);
[Engine], null, null);
}
}

Expand All @@ -86,15 +84,15 @@ private FhirJsonConverter(IFhirSerializationEngine engine)
{
this._engine = (PocoSerializationEngine)engine;
}

/// <summary>
/// Constructs a <see cref="JsonConverter{T}"/> that (de)serializes FHIR json for the
/// POCOs in a given assembly.
/// </summary>
/// <param name="assembly">The assembly containing classes to be used for deserialization.</param>
[Obsolete("Using this directly is not recommended. Instead, try creating a converter using the .ForFhir static method of the JsonSerializerOptions class")]
public FhirJsonConverter(
Assembly assembly): this(ModelInspector.ForAssembly(assembly))
Assembly assembly) : this(ModelInspector.ForAssembly(assembly))
{
// nothing
}
Expand All @@ -103,7 +101,8 @@ public FhirJsonConverter(
public FhirJsonConverter(
Assembly assembly, FhirJsonPocoSerializerSettings? serializerSettings = null, FhirJsonPocoDeserializerSettings? deserializerSettings = null,
Predicate<CodedException>? ignoreFilter = null) :
this(FhirSerializationEngineFactory.Custom(ModelInspector.ForAssembly(assembly), ignoreFilter ?? (_ => false), deserializerSettings, serializerSettings)){}
this(FhirSerializationEngineFactory.Custom(ModelInspector.ForAssembly(assembly), ignoreFilter ?? (_ => false), deserializerSettings, serializerSettings))
{ }

/// <summary>
/// Constructs a <see cref="JsonConverter{T}"/> that (de)serializes FHIR json for the
Expand Down Expand Up @@ -160,5 +159,4 @@ public override F Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial
}
}

#endif
#nullable restore
4 changes: 1 addition & 3 deletions src/Hl7.Fhir.Base/Serialization/FhirJsonException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/


#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER
using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
using Hl7.Fhir.Validation;
Expand Down Expand Up @@ -208,5 +207,4 @@ internal static FhirJsonException Initialize(ref Utf8JsonReader reader, string i
}
}

#nullable restore
#endif
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
*/


#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

#nullable enable

using Hl7.Fhir.Model;
using Hl7.Fhir.Validation;
using System;
using System.Collections.Generic;
using System.Text.Json;

namespace Hl7.Fhir.Serialization
Expand Down Expand Up @@ -81,5 +77,4 @@ public delegate (object?, FhirJsonException?) PrimitiveParseHandler(
FhirJsonException originalException);
}

#nullable restore
#endif
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
*/


#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

#nullable enable

using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
using Hl7.Fhir.Validation;
using System;
using System.Text.Json;
#nullable enable

namespace Hl7.Fhir.Serialization
{
Expand All @@ -31,5 +25,4 @@ public record FhirJsonPocoSerializerSettings
}
}

#nullable restore
#endif
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

#nullable enable

#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

using Hl7.Fhir.Introspection;
using Hl7.Fhir.Model;
using Hl7.Fhir.Model.CdsHooks;
using Hl7.Fhir.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -239,5 +236,4 @@ public enum DeserializerModes
}
}

#endif
#nullable restore
12 changes: 2 additions & 10 deletions src/Hl7.Fhir.Base/Serialization/SystemTextJsonParsingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
*/


#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.Json;
#nullable enable

Expand Down Expand Up @@ -65,13 +62,9 @@ public static bool TryGetNumber(this ref Utf8JsonReader reader, [NotNullWhen(tru
return gotValue;
}

#if NETSTANDARD2_0
internal static bool IsNormal(this float f) => !float.IsNaN(f) && !float.IsInfinity(f);
internal static bool IsNormal(this double d) => !double.IsNaN(d) && !double.IsInfinity(d);
#else

internal static bool IsNormal(this float f) => float.IsNormal(f);
internal static bool IsNormal(this double d) => double.IsNormal(d);
#endif

public static void Recover(this ref Utf8JsonReader reader)
{
Expand Down Expand Up @@ -115,5 +108,4 @@ public static void SkipTo(this ref Utf8JsonReader reader, JsonTokenType tt)

}

#nullable restore
#endif
#nullable restore
2 changes: 0 additions & 2 deletions src/Hl7.Fhir.Base/Utility/PropertyInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public static Func<T, object> GetValueGetter<T>(this PropertyInfo propertyInfo)
/// </summary>
public static Action<object, object?> GetValueSetter(this PropertyInfo propertyInfo) => GetValueSetter<object>(propertyInfo);

#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

public static Func<C, T> GetField<C, T>(string fieldName)
{
Expand Down Expand Up @@ -218,7 +217,6 @@ public static Func<C, T> GetField<C, T>(string fieldName)

T getField(C instance) => (T)field.GetValue(instance)!;
}
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ private static ValidationResult runValidateXhtmlSchema(string text, ValidationCo
try
{
var doc = SerializationUtil.XDocumentFromXmlText(text);

#if NETSTANDARD1_6
var errors = new string[0];
#else
var errors = SerializationUtil.RunFhirXhtmlSchemaValidation(doc);
#endif

return errors.Any() ? COVE.NARRATIVE_XML_IS_INVALID(context, string.Join(", ", errors)).AsResult(context) : ValidationResult.Success!;
}
catch (FormatException fe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#nullable enable

#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

using Hl7.Fhir.Model;
using System.Text.Json;
Expand Down Expand Up @@ -60,5 +59,4 @@ public static JsonSerializerOptions ForFhir(
}
}

#endif
#nullable restore

0 comments on commit 090d26a

Please sign in to comment.