From a7bee103a0a971b0d4bc4f6f0cc63dce0a1e6b93 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Wed, 11 Mar 2020 14:53:57 +0300 Subject: [PATCH 1/6] Broke tests --- tests/MongoDB.Bson.FSharp.Tests/TestItems.fs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/MongoDB.Bson.FSharp.Tests/TestItems.fs b/tests/MongoDB.Bson.FSharp.Tests/TestItems.fs index 5ac6664..ff2eb9e 100644 --- a/tests/MongoDB.Bson.FSharp.Tests/TestItems.fs +++ b/tests/MongoDB.Bson.FSharp.Tests/TestItems.fs @@ -4,6 +4,11 @@ type TestResult<'a> = | Failure | Result of cause: string * nr : 'a | NoResults of string + +type TestRecord = + { + Foo: string + } type TestItem = { Id : int @@ -12,6 +17,7 @@ type TestItem = Array : int array RecursiveOpt : TestItem option Union : TestResult + ComplexUnion : TestResult MapStringInt : Map MapIntString : Map SetInt: int Set @@ -30,6 +36,7 @@ let testItem = Array = [|10;20;30|] RecursiveOpt = None Union = Result ("just", 5) + ComplexUnion = Result ("bar", {Foo = "foo"}) MapStringInt = [("one", 1);("two", 2)] |> Map.ofList MapIntString = [(5, "five"); (1, "one")] |> Map.ofList SetInt = Set.empty @@ -49,6 +56,7 @@ let testItems = Array = [||] RecursiveOpt = Some parent Union = NoResults "just because" + ComplexUnion = NoResults "tested already" MapIntString = Map.empty MapStringInt = Map.empty SetInt = [9;8;7] |> Set.ofList From c698c6c6052e72a682af179881a0ef5c086a5e32 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Wed, 11 Mar 2020 15:11:55 +0300 Subject: [PATCH 2/6] Move RecordSerializer back --- .../MongoDB.Bson.FSharp.fs | 67 +++++++++---------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs b/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs index eece932..f25b2d5 100644 --- a/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs +++ b/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs @@ -129,39 +129,31 @@ type DictionaryRepresentationConvention(representation : DictionaryRepresentatio |> ignore -// type RecordSerializer<'TRecord>() = - -// inherit SerializerBase<'TRecord>() -// let classMap = BsonClassMap.LookupClassMap(typeof<'TRecord>) -// let serializer = BsonClassMapSerializer(classMap) -// let fields = GetRecordFields typeof<'TRecord> - -// override this.Serialize(context, args, value) = -// let recordType = -// let t = typeof<'TRecord> -// printfn "deserialize record %A = %A" t.Name value -// t -// let mutable nargs = args -// nargs.NominalType <- typeof<'TRecord> -// serializer.Serialize(context, nargs, value) - -// override this.Deserialize(context, args) = -// let recordType = -// let t = typeof<'TRecord> -// printfn "deserialize record %A" t.Name -// t -// let mutable nargs = args -// nargs.NominalType <- typeof<'TRecord> -// serializer.Deserialize(context, nargs) - -// interface IBsonDocumentSerializer with -// member x.TryGetMemberSerializationInfo(memberName, serializationInfo) = -// if Array.exists (fun (el: PropertyInfo) -> el.Name = memberName) fields then -// let mm = classMap.GetMemberMap(memberName) -// serializationInfo <- new BsonSerializationInfo(mm.ElementName, mm.GetSerializer(), mm.MemberType) -// true -// else -// false + type RecordSerializer<'TRecord>() = + + inherit SerializerBase<'TRecord>() + let classMap = BsonClassMap.LookupClassMap(typeof<'TRecord>) + let serializer = BsonClassMapSerializer(classMap) + let fields = GetRecordFields typeof<'TRecord> + + override this.Serialize(context, args, value) = + let mutable nargs = args + nargs.NominalType <- typeof<'TRecord> + serializer.Serialize(context, nargs, value) + + override this.Deserialize(context, args) = + let mutable nargs = args + nargs.NominalType <- typeof<'TRecord> + serializer.Deserialize(context, nargs) + + interface IBsonDocumentSerializer with + member x.TryGetMemberSerializationInfo(memberName, serializationInfo) = + if Array.exists (fun (el: PropertyInfo) -> el.Name = memberName) fields then + let mm = classMap.GetMemberMap(memberName) + serializationInfo <- BsonSerializationInfo(mm.ElementName, mm.GetSerializer(), mm.MemberType) + true + else + false type DiscriminatedUnionSerializer<'t>() = inherit SerializerBase<'t>() @@ -173,7 +165,8 @@ type DiscriminatedUnionSerializer<'t>() = BsonSerializer.LookupSerializer(t).Deserialize(context, args) let serBy context args t v = - BsonSerializer.LookupSerializer(t).Serialize(context, args, v) + let ser = BsonSerializer.LookupSerializer(t) + ser.Serialize(context, args, v) let readItems context args types = types @@ -299,9 +292,9 @@ type FSharpTypeSerializationProvider() = elif IsUnion objType then typedefof>.MakeGenericType(objType) |> createSerializer - // elif IsRecord objType then - // typedefof>.MakeGenericType(objType) - // |> createSerializer + elif IsRecord objType then + typedefof>.MakeGenericType(objType) + |> createSerializer else null From e3ce2b1b0b45a3eeea8d5e344278f049f7a05743 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Wed, 11 Mar 2020 15:38:32 +0300 Subject: [PATCH 3/6] Update version --- RELEASE_NOTES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 53e2303..198e789 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +#### 0.0.5-beta - 11 march 2020 + +* Fix problems with Record types in Union types + #### 0.0.4-beta - 25 Juny 2018 * Support netstandard2.0 From d89993dc3a76961ad5d506c415ba2c83c21221f1 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Wed, 11 Mar 2020 15:39:21 +0300 Subject: [PATCH 4/6] Update version in project --- src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fsproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fsproj b/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fsproj index 1436c2f..610dde7 100644 --- a/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fsproj +++ b/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fsproj @@ -5,7 +5,7 @@ true - 0.0.4-beta + 0.0.5-beta MongoDB.Bson.FSharp MongoDB Bson serializers for F# types Official MongoDB.Bson package contains no preconfigured serializers supporting typical F# types. This package tries to close the gap From 8fa736d6dbfca1144e4f467c0443ba71ccf74112 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Wed, 11 Mar 2020 15:39:51 +0300 Subject: [PATCH 5/6] Reformat paket targets --- .paket/Paket.Restore.targets | 91 ++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/.paket/Paket.Restore.targets b/.paket/Paket.Restore.targets index a795558..8d37e28 100644 --- a/.paket/Paket.Restore.targets +++ b/.paket/Paket.Restore.targets @@ -20,18 +20,18 @@ proj assembly native - /Library/Frameworks/Mono.framework/Commands/mono + /Library/Frameworks/Mono.framework/Commands/mono mono $(PaketRootPath)paket.bootstrapper.exe $(PaketToolsPath)paket.bootstrapper.exe $([System.IO.Path]::GetDirectoryName("$(PaketBootStrapperExePath)"))\ - - "$(PaketBootStrapperExePath)" + + "$(PaketBootStrapperExePath)" $(MonoPath) --runtime=v4.0.30319 "$(PaketBootStrapperExePath)" - + true @@ -40,55 +40,68 @@ True + + False + $(BaseIntermediateOutputPath.TrimEnd('\').TrimEnd('\/')) - + + - - - - - + + + + $(PaketRootPath)paket + $(PaketToolsPath)paket + - - - dotnet paket + + + + $(PaketRootPath)paket.exe + $(PaketToolsPath)paket.exe - - - - $(PaketRootPath)paket.exe - $(PaketToolsPath)paket.exe - $(PaketToolsPath)paket.exe - $(_PaketBootStrapperExeDir)paket.exe - paket.exe + + + + <_DotnetToolsJson Condition="Exists('$(PaketRootPath)/.config/dotnet-tools.json')">$([System.IO.File]::ReadAllText("$(PaketRootPath)/.config/dotnet-tools.json")) + <_ConfigContainsPaket Condition=" '$(_DotnetToolsJson)' != ''">$(_DotnetToolsJson.Contains('"paket"')) + <_ConfigContainsPaket Condition=" '$(_ConfigContainsPaket)' == ''">false + - - $(PaketRootPath)paket - $(PaketToolsPath)paket - $(PaketToolsPath)paket + + + + + - - $(PaketRootPath)paket.exe - $(PaketToolsPath)paket.exe + + + <_PaketCommand>dotnet paket + - - $(PaketBootStrapperExeDir)paket.exe + + + + $(PaketToolsPath)paket + $(PaketBootStrapperExeDir)paket - - paket + + paket + + + <_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)")) - dotnet "$(PaketExePath)" - $(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" - "$(PaketExePath)" - + <_PaketCommand Condition=" '$(_PaketCommand)' == '' AND '$(_PaketExeExtension)' == '.dll' ">dotnet "$(PaketExePath)" + <_PaketCommand Condition=" '$(_PaketCommand)' == '' AND '$(OS)' != 'Windows_NT' AND '$(_PaketExeExtension)' == '.exe' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" + <_PaketCommand Condition=" '$(_PaketCommand)' == '' ">"$(PaketExePath)" - + @@ -123,7 +136,7 @@ - $([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[0].Replace(`"`, ``).Replace(` `, ``)) $([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[1].Replace(`"`, ``).Replace(` `, ``)) @@ -156,7 +169,7 @@ - + From f3261351fedc8277be84443d9730dd037163db59 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Wed, 11 Mar 2020 16:16:15 +0300 Subject: [PATCH 6/6] Remove redundant value --- src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs b/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs index f25b2d5..0a07c2d 100644 --- a/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs +++ b/src/MongoDB.Bson.FSharp/MongoDB.Bson.FSharp.fs @@ -165,8 +165,7 @@ type DiscriminatedUnionSerializer<'t>() = BsonSerializer.LookupSerializer(t).Deserialize(context, args) let serBy context args t v = - let ser = BsonSerializer.LookupSerializer(t) - ser.Serialize(context, args, v) + BsonSerializer.LookupSerializer(t).Serialize(context, args, v) let readItems context args types = types