Skip to content

Commit

Permalink
add support for netstandard2.1 / net8 / net9
Browse files Browse the repository at this point in the history
  • Loading branch information
pchalamet committed Jan 1, 2025
1 parent 70f2be5 commit eda3992
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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].
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.MongoDB.Bson/FSharp.MongoDB.Bson.fsproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/FSharp.MongoDB.Bson/Serialization/FSharpTypeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit eda3992

Please sign in to comment.