diff --git a/README.md b/README.md index 8b6463d..0e37cea 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,9 @@ Repository origins are: ## Supported platforms -This project targets `netstandard2.1` ([compatible runtimes](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-1#select-net-standard-version)). +This project targets `.net 8`, `.net 9` and `netstandard2.1` ([compatible runtimes](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-1#select-net-standard-version)) + +:warning: NRT support starts with `.net sdk 9.0.200`. F# compiler in .net sdk 9.0.10x does not set correctly nullable attributes on F# types. NRT are not supported on `netstandard2.1`. ## Contributing * If you have a question about the library, then create an [issue][issues] with the `question` label. @@ -89,7 +91,9 @@ NRT are serialized as: * `null` if `Null` * `object` if `NonNull` object -:warning: As of now, NRT can't be considered `null` when deserializing if value is missing. +On deserialization, missing value is mapped to `null`. + +:warning: NRT support starts with .net sdk 9.0.200. F# compiler in .net sdk 9.0.10x does not set correctly nullable attributes on F# types. # License The contents of this library are made available under the [Apache License, Version 2.0][license]. diff --git a/src/FSharp.MongoDB.Bson/FSharp.MongoDB.Bson.fsproj b/src/FSharp.MongoDB.Bson/FSharp.MongoDB.Bson.fsproj index e617507..820c4f8 100644 --- a/src/FSharp.MongoDB.Bson/FSharp.MongoDB.Bson.fsproj +++ b/src/FSharp.MongoDB.Bson/FSharp.MongoDB.Bson.fsproj @@ -1,7 +1,7 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFrameworks>net9.0;net8.0</TargetFrameworks> + <TargetFrameworks>net9.0;net8.0;netstandard2.1</TargetFrameworks> <GenerateDocumentationFile>true</GenerateDocumentationFile> <Nullable>enable</Nullable> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> diff --git a/src/FSharp.MongoDB.Bson/Serialization/FSharpTypeHelpers.fs b/src/FSharp.MongoDB.Bson/Serialization/FSharpTypeHelpers.fs index 515a241..92a1d99 100644 --- a/src/FSharp.MongoDB.Bson/Serialization/FSharpTypeHelpers.fs +++ b/src/FSharp.MongoDB.Bson/Serialization/FSharpTypeHelpers.fs @@ -23,7 +23,9 @@ module private Helpers = let bindingFlags = BindingFlags.Public ||| BindingFlags.NonPublic +#if !NETSTANDARD2_1 let nrtContext = NullabilityInfoContext() +#endif /// <summary> /// Returns <c>Some typ</c> when <c>pred typ</c> returns true, and <c>None</c> when @@ -95,6 +97,10 @@ module private Helpers = let mkMemberNullable (memberMap: BsonClassMap) (propertyInfo: PropertyInfo) = let memberMap = memberMap.MapMember(propertyInfo) +#if !NETSTANDARD2_1 let nrtInfo = nrtContext.Create(propertyInfo) if nrtInfo.WriteState = NullabilityState.Nullable then memberMap.SetDefaultValue(null).SetIsRequired(false) |> ignore +#else + () +#endif