File tree Expand file tree Collapse file tree 3 files changed +10
-15
lines changed
src/FSharp.MongoDB.Bson/Serialization Expand file tree Collapse file tree 3 files changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,6 @@ open System.Reflection
27
27
type FSharpRecordConvention () =
28
28
inherit ConventionBase()
29
29
30
- static let nrtContext = NullabilityInfoContext()
31
-
32
30
interface IClassMapConvention with
33
31
member _.Apply classMap =
34
32
match classMap.ClassType with
@@ -41,9 +39,5 @@ type FSharpRecordConvention() =
41
39
classMap.MapConstructor( ctor, names) |> ignore
42
40
43
41
// Map each field of the record type.
44
- fields |> Array.iter ( fun pi ->
45
- let memberMap = classMap.MapMember( pi)
46
- let nrtInfo = nrtContext.Create( pi)
47
- if nrtInfo.WriteState = NullabilityState.Nullable then
48
- memberMap.SetDefaultValue( null ) .SetIsRequired( false ) |> ignore)
42
+ fields |> Array.iter ( mkMemberNullable classMap)
49
43
| _ -> ()
Original file line number Diff line number Diff line change @@ -30,8 +30,6 @@ open MongoDB.Bson.Serialization.Helpers
30
30
type UnionCaseConvention () =
31
31
inherit ConventionBase()
32
32
33
- static let nrtContext = NullabilityInfoContext()
34
-
35
33
let tryGetUnionCase ( typ : System.Type ) =
36
34
// 8.5.4. Compiled Form of Union Types for Use from Other CLI Languages
37
35
// A compiled union type U has [o]ne CLI nested type U.C for each non-null union case C.
@@ -78,12 +76,7 @@ type UnionCaseConvention() =
78
76
classMap.MapCreator( del, names) |> ignore
79
77
80
78
// Map each field of the union case.
81
- // Map each field of the record type.
82
- fields |> Array.iter ( fun pi ->
83
- let memberMap = classMap.MapMember( pi)
84
- let nrtInfo = nrtContext.Create( pi)
85
- if nrtInfo.WriteState = NullabilityState.Nullable then
86
- memberMap.SetDefaultValue( null ) .SetIsRequired( false ) |> ignore)
79
+ fields |> Array.iter ( mkMemberNullable classMap)
87
80
88
81
interface IClassMapConvention with
89
82
member _.Apply classMap =
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ module private Helpers =
23
23
24
24
let bindingFlags = BindingFlags.Public ||| BindingFlags.NonPublic
25
25
26
+ let nrtContext = NullabilityInfoContext()
27
+
26
28
/// <summary>
27
29
/// Returns <c>Some typ</c> when <c>pred typ</c> returns true, and <c>None</c> when
28
30
/// <c>pred typ</c> returns false.
@@ -90,3 +92,9 @@ module private Helpers =
90
92
/// Creates a generic type <c>'T</c> using the generic arguments of <c>typ</c>.
91
93
/// </summary>
92
94
let mkGenericUsingDef < 'T > ( typ : System.Type ) = typ.GetGenericArguments() |> mkGeneric< 'T>
95
+
96
+ let mkMemberNullable ( memberMap : BsonClassMap ) ( propertyInfo : PropertyInfo ) =
97
+ let memberMap = memberMap.MapMember( propertyInfo)
98
+ let nrtInfo = nrtContext.Create( propertyInfo)
99
+ if nrtInfo.WriteState = NullabilityState.Nullable then
100
+ memberMap.SetDefaultValue( null ) .SetIsRequired( false ) |> ignore
You can’t perform that action at this time.
0 commit comments