File tree Expand file tree Collapse file tree 6 files changed +28
-14
lines changed
tests/FSharp.MongoDB.Bson.Tests Expand file tree Collapse file tree 6 files changed +28
-14
lines changed Original file line number Diff line number Diff line change 44 <TargetFramework >netstandard2.1</TargetFramework >
55 <GenerateDocumentationFile >true</GenerateDocumentationFile >
66 <Nullable >enable</Nullable >
7+ <TreatWarningsAsErrors >true</TreatWarningsAsErrors >
78 </PropertyGroup >
89
910 <ItemGroup >
Original file line number Diff line number Diff line change @@ -34,17 +34,21 @@ module private Helpers =
3434 /// <summary >
3535 /// Returns <c >Some typ</c > when <c >typ</c > is a record type, and <c >None</c > otherwise.
3636 /// </summary >
37- let (| IsRecord | _ |) typ =
38- let isRecord typ = typ <> null && FSharpType.IsRecord( typ, bindingFlags)
39- whenType isRecord typ
37+ let (| IsRecord | _ |) = function
38+ | Null -> None
39+ | NonNull typ ->
40+ let isRecord typ = FSharpType.IsRecord( typ, bindingFlags)
41+ whenType isRecord typ
4042
4143 /// <summary >
4244 /// Returns <c >Some typ</c > when <c >typ</c > is a top-level union type or when it represents a
4345 /// particular union case, and <c >None</c > otherwise.
4446 /// </summary >
45- let (| IsUnion | _ |) ( typ : System.Type ) =
46- let isUnion typ = typ <> null && FSharpType.IsUnion( typ, bindingFlags)
47- whenType isUnion typ
47+ let (| IsUnion | _ |) = function
48+ | Null -> None
49+ | NonNull typ ->
50+ let isUnion typ = FSharpType.IsUnion( typ, bindingFlags)
51+ whenType isUnion typ
4852
4953 /// <summary >
5054 /// Returns true if <c >typ</c > is a generic type with defintion <c >'GenericType</c >.
Original file line number Diff line number Diff line change @@ -38,9 +38,10 @@ module FSharpValueSerializer =
3838 interface IBsonSerializationProvider with
3939
4040 member __.GetSerializer typ =
41- let mkSerializer = function
42- | Some ( typ: System.Type) -> System.Activator.CreateInstance typ :?> IBsonSerializer
43- | None -> null
41+ let mkSerializer typ =
42+ typ
43+ |> Option.map ( fun typ -> System.Activator.CreateInstance typ :?> IBsonSerializer)
44+ |> Option.toObj
4445
4546 match typ with
4647 | IsList typ -> Some ( mkGenericUsingDef< FSharpListSerializer<_>> typ)
Original file line number Diff line number Diff line change 22<Project Sdk =" Microsoft.NET.Sdk" >
33 <PropertyGroup >
44 <TargetFramework >net9.0</TargetFramework >
5- <GenerateProgramFile >false</GenerateProgramFile >
65 <Nullable >enable</Nullable >
6+ <TreatWarningsAsErrors >true</TreatWarningsAsErrors >
77 </PropertyGroup >
88
99 <ItemGroup >
Original file line number Diff line number Diff line change @@ -87,13 +87,17 @@ module FSharpListSerialization =
8787 let value = { MaybeStrings = [ Some " a" ; None; Some " z" ] }
8888
8989 let result = serialize value
90- let expected = BsonDocument( " MaybeStrings" , BsonArray [ " a" ; null ; " z" ])
90+ let expected =
91+ let values : ( string | null ) array = [| " a" ; null ; " z" |]
92+ BsonDocument( " MaybeStrings" , BsonArray values)
9193
9294 result |> should equal expected
9395
9496 [<Test>]
9597 let ``test deserialize a list of optional strings`` () =
96- let doc = BsonDocument( " MaybeStrings" , BsonArray [ " a" ; null ; " z" ])
98+ let doc =
99+ let values : ( string | null ) array = [| " a" ; null ; " z" |]
100+ BsonDocument( " MaybeStrings" , BsonArray values)
97101
98102 let result = deserialize doc typeof< Record>
99103 let expected = { MaybeStrings = [ Some " a" ; None; Some " z" ] }
Original file line number Diff line number Diff line change @@ -87,13 +87,17 @@ module FSharpSetSerialization =
8787 let value = { MaybeStrings = Set.ofList [ Some " a" ; None; Some " z" ] }
8888
8989 let result = serialize value
90- let expected = BsonDocument( " MaybeStrings" , BsonArray ( Set.ofList [ " a" ; null ; " z" ]))
90+ let expected =
91+ let values : ( string | null ) list = [ " a" ; null ; " z" ]
92+ BsonDocument( " MaybeStrings" , BsonArray ( Set.ofList values))
9193
9294 result |> should equal expected
9395
9496 [<Test>]
9597 let ``test deserialize a set of optional strings`` () =
96- let doc = BsonDocument( " MaybeStrings" , BsonArray [ " a" ; null ; " z" ])
98+ let doc =
99+ let values : ( string | null ) list = [ " a" ; null ; " z" ]
100+ BsonDocument( " MaybeStrings" , BsonArray values)
97101
98102 let result = deserialize doc typeof< Record>
99103 let expected = { MaybeStrings = Set.ofList [ Some " a" ; None; Some " z" ] }
You can’t perform that action at this time.
0 commit comments