Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pchalamet committed Jan 1, 2025
1 parent 99ab49e commit 8741ae1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace MongoDB.Bson.Serialization.Conventions
open Microsoft.FSharp.Reflection
open MongoDB.Bson.Serialization.Conventions
open MongoDB.Bson.Serialization.Helpers
open System.Reflection

/// <summary>
/// Convention for F# record types that initializes a <c>BsonClassMap</c> by mapping the record
Expand All @@ -32,12 +31,12 @@ type FSharpRecordConvention() =
match classMap.ClassType with
| IsRecord typ ->
let fields = FSharpType.GetRecordFields(typ, bindingFlags)
let names = fields |> Array.map (fun x -> x.Name)
let names = fields |> Array.map _.Name

// Map the constructor of the record type.
let ctor = FSharpValue.PreComputeRecordConstructorInfo(typ, bindingFlags)
classMap.MapConstructor(ctor, names) |> ignore

// Map each field of the record type.
fields |> Array.iter (mkMemberNullable classMap)
fields |> Array.iter (mapMemberNullable classMap)
| _ -> ()
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type UnionCaseConvention() =

let mapUnionCase (classMap:BsonClassMap) (unionCase:UnionCaseInfo) =
let fields = unionCase.GetFields()
let names = fields |> Array.map (fun x -> x.Name)
let names = fields |> Array.map _.Name

classMap.SetDiscriminator unionCase.Name
classMap.SetDiscriminatorIsRequired true
Expand All @@ -76,7 +76,7 @@ type UnionCaseConvention() =
classMap.MapCreator(del, names) |> ignore

// Map each field of the union case.
fields |> Array.iter (mkMemberNullable classMap)
fields |> Array.iter (mapMemberNullable classMap)

interface IClassMapConvention with
member _.Apply classMap =
Expand Down
5 changes: 4 additions & 1 deletion src/FSharp.MongoDB.Bson/Serialization/FSharpTypeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ module private Helpers =
/// </summary>
let mkGenericUsingDef<'T> (typ:System.Type) = typ.GetGenericArguments() |> mkGeneric<'T>

let mkMemberNullable (memberMap: BsonClassMap) (propertyInfo: PropertyInfo) =
/// <summary>
/// Maps a member of a <c>BsonClassMap</c> to a nullable value if possible.
/// </summary>
let mapMemberNullable (memberMap: BsonClassMap) (propertyInfo: PropertyInfo) =
let memberMap = memberMap.MapMember(propertyInfo)
#if !NETSTANDARD2_1
let nrtInfo = nrtContext.Create(propertyInfo)
Expand Down

0 comments on commit 8741ae1

Please sign in to comment.