Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use static interfaces, remove AdHoc Encoding. #132

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core 6
- name: Setup .NET Core 7
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.300
dotnet-version: 7.0.100
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release
- name: Test SystemJson
run: dotnet run --no-build --project ./test/Tests.SystemJson/Tests.SystemJson.fsproj -c Release -f net6
run: dotnet run --no-build --project ./test/Tests.SystemJson/Tests.SystemJson.fsproj -c Release -f net7
- name: Test FSharpData
run: dotnet run --no-build --project ./test/Tests.FSharpData/Tests.FSharpData.fsproj -c Release -f net6
run: dotnet run --no-build --project ./test/Tests.FSharpData/Tests.FSharpData.fsproj -c Release -f net7
- name: Test NewtonsoftJson
run: dotnet run --no-build --project ./test/Tests.NewtonsoftJson/Tests.NewtonsoftJson.fsproj -c Release -f net6
run: dotnet run --no-build --project ./test/Tests.NewtonsoftJson/Tests.NewtonsoftJson.fsproj -c Release -f net7
- name: Test SystemTextJson
run: dotnet run --no-build --project ./test/Tests.SystemTextJson/Tests.SystemTextJson.fsproj -c Release -f net6
run: dotnet run --no-build --project ./test/Tests.SystemTextJson/Tests.SystemTextJson.fsproj -c Release -f net7
- name: Test Integration
run: dotnet run --no-build --project ./test/IntegrationCompilationTests/IntegrationCompilationTests.fsproj -c Release -f net6
run: dotnet run --no-build --project ./test/IntegrationCompilationTests/IntegrationCompilationTests.fsproj -c Release -f net7

docs:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core 6
- name: Setup .NET Core 7
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.300
dotnet-version: 7.0.100
- name: Restore dotnet tools
run: dotnet tool restore
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/Benchmarks.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net7</TargetFramework>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>

Expand Down
15 changes: 6 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ build_script:
- cmd: echo vs %VersionSuffix%"
- cmd: build.bat
test_script:
- cmd: dotnet run --project .\test\Tests.SystemJson\Tests.SystemJson.fsproj -c Release -f net461
- cmd: dotnet run --project .\test\Tests.SystemJson\Tests.SystemJson.fsproj -c Release -f net6
- cmd: dotnet run --project .\test\Tests.FSharpData\Tests.FSharpData.fsproj -c Release -f net6
- cmd: dotnet run --project .\test\Tests.FSharpData\Tests.FSharpData.fsproj -c Release -f netcoreapp31
- cmd: dotnet run --project .\test\Tests.NewtonsoftJson\Tests.NewtonsoftJson.fsproj -c Release -f net6
- cmd: dotnet run --project .\test\Tests.NewtonsoftJson\Tests.NewtonsoftJson.fsproj -c Release -f netcoreapp31
- cmd: dotnet run --project .\test\Tests.SystemTextJson\Tests.SystemTextJson.fsproj -c Release -f net6
- cmd: dotnet run --project .\test\Tests.SystemTextJson\Tests.SystemTextJson.fsproj -c Release -f netcoreapp31
- cmd: dotnet run --project .\test\IntegrationCompilationTests\IntegrationCompilationTests.fsproj -c Release -f net6
- cmd: dotnet run --project .\test\Tests.SystemJson\Tests.SystemJson.fsproj -c Release -f net7
- cmd: dotnet run --project .\test\Tests.FSharpData\Tests.FSharpData.fsproj -c Release -f net7
- cmd: dotnet run --project .\test\Tests.FSharpData\Tests.FSharpData.fsproj -c Release -f net7
- cmd: dotnet run --project .\test\Tests.NewtonsoftJson\Tests.NewtonsoftJson.fsproj -c Release -f net7
- cmd: dotnet run --project .\test\Tests.SystemTextJson\Tests.SystemTextJson.fsproj -c Release -f net7
- cmd: dotnet run --project .\test\IntegrationCompilationTests\IntegrationCompilationTests.fsproj -c Release -f net7

artifacts:
# pushing all *.nupkg files in build directory recursively
Expand Down
2 changes: 1 addition & 1 deletion docsrc/docs/docs.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net7</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion docsrc/tool/docsTool.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net7</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.0",
"version": "7.0.0",
"rollForward": "latestMinor"
}
}
66 changes: 33 additions & 33 deletions src/Fleece.FSharpData/Fleece.FSharpData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ type [<Struct>] Encoding = Encoding of JsonValue with
| js -> Decode.Fail.numExpected (Encoding js)

/// Unwraps the JsonValue inside an IEncoding
static member Unwrap (x: IEncoding) = x :?> Encoding |> fun (Encoding s) -> s
static member Unwrap (Encoding s) = s

/// Wraps a JsonValue inside an IEncoding
static member Wrap x = Encoding x :> IEncoding
static member Wrap x = Encoding x

static member toIEncoding (c: Codec<JsonValue, 't>) : Codec<IEncoding, 't> = c |> Codec.compose ((Encoding.Unwrap >> Ok) <-> Encoding.Wrap)
static member ofIEncoding (c: Codec<IEncoding, 't>) : Codec<JsonValue, 't> = c |> Codec.compose ((Encoding.Wrap >> Ok) <-> Encoding.Unwrap)
static member toIEncoding (c: Codec<JsonValue, 't>) : Codec<Encoding, 't> = c |> Codec.compose ((Encoding.Unwrap >> Ok) <-> Encoding.Wrap)
static member ofIEncoding (c: Codec<Encoding, 't>) : Codec<JsonValue, 't> = c |> Codec.compose ((Encoding.Wrap >> Ok) <-> Encoding.Unwrap)

static member jsonObjectOfJson = function
| JObject x -> Ok (dictAsJsonObject x)
Expand Down Expand Up @@ -328,39 +328,39 @@ type [<Struct>] Encoding = Encoding of JsonValue with
static member guid = Encoding.guidD <-> Encoding.guidE


interface IEncoding with
member _.boolean = Encoding.toIEncoding Encoding.boolean
member _.string = Encoding.toIEncoding Encoding.string
member _.dateTime t =
interface IEncoding<Encoding> with
static member boolean = Encoding.toIEncoding Encoding.boolean
static member string = Encoding.toIEncoding Encoding.string
static member dateTime t =
match t with
| Some DateTimeContents.Date -> Encoding.toIEncoding Encoding.date
| Some DateTimeContents.Time -> Encoding.toIEncoding Encoding.time
| _ -> Encoding.toIEncoding Encoding.dateTime
member _.dateTimeOffset = Encoding.toIEncoding Encoding.dateTimeOffset
member _.timeSpan = Encoding.toIEncoding Encoding.timeSpan
member _.decimal = Encoding.toIEncoding Encoding.decimal
member _.float = Encoding.toIEncoding Encoding.float
member _.float32 = Encoding.toIEncoding Encoding.float32
member _.int = Encoding.toIEncoding Encoding.int
member _.uint32 = Encoding.toIEncoding Encoding.uint32
member _.int64 = Encoding.toIEncoding Encoding.int64
member _.uint64 = Encoding.toIEncoding Encoding.uint64
member _.int16 = Encoding.toIEncoding Encoding.int16
member _.uint16 = Encoding.toIEncoding Encoding.uint16
member _.byte = Encoding.toIEncoding Encoding.byte
member _.sbyte = Encoding.toIEncoding Encoding.sbyte
member _.char = Encoding.toIEncoding Encoding.char
member _.bigint = Encoding.toIEncoding Encoding.bigint
member _.guid = Encoding.toIEncoding Encoding.guid

member _.result c1 c2 = Encoding.toIEncoding (Encoding.result (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
member _.choice c1 c2 = Encoding.toIEncoding (Encoding.choice (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
member _.choice3 c1 c2 c3 = Encoding.toIEncoding (Encoding.choice3 (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2) (Encoding.ofIEncoding c3))
member _.option c = Encoding.toIEncoding (Encoding.option (Encoding.ofIEncoding c))
member _.array c = Encoding.toIEncoding (Encoding.array (Encoding.ofIEncoding c))
member _.propertyList c = Encoding.toIEncoding (Encoding.multiMap (Encoding.ofIEncoding c))

member _.enum<'t, 'u when 't : enum<'u> and 't : (new : unit -> 't) and 't : struct and 't :> ValueType> () : Codec<IEncoding, 't> = Encoding.toIEncoding (Encoding.enumD <-> Encoding.enumE)
static member dateTimeOffset = Encoding.toIEncoding Encoding.dateTimeOffset
static member timeSpan = Encoding.toIEncoding Encoding.timeSpan
static member decimal = Encoding.toIEncoding Encoding.decimal
static member float = Encoding.toIEncoding Encoding.float
static member float32 = Encoding.toIEncoding Encoding.float32
static member int = Encoding.toIEncoding Encoding.int
static member uint32 = Encoding.toIEncoding Encoding.uint32
static member int64 = Encoding.toIEncoding Encoding.int64
static member uint64 = Encoding.toIEncoding Encoding.uint64
static member int16 = Encoding.toIEncoding Encoding.int16
static member uint16 = Encoding.toIEncoding Encoding.uint16
static member byte = Encoding.toIEncoding Encoding.byte
static member sbyte = Encoding.toIEncoding Encoding.sbyte
static member char = Encoding.toIEncoding Encoding.char
static member bigint = Encoding.toIEncoding Encoding.bigint
static member guid = Encoding.toIEncoding Encoding.guid

static member result c1 c2 = Encoding.toIEncoding (Encoding.result (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
static member choice c1 c2 = Encoding.toIEncoding (Encoding.choice (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
static member choice3 c1 c2 c3 = Encoding.toIEncoding (Encoding.choice3 (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2) (Encoding.ofIEncoding c3))
static member option c = Encoding.toIEncoding (Encoding.option (Encoding.ofIEncoding c))
static member array c = Encoding.toIEncoding (Encoding.array (Encoding.ofIEncoding c))
static member propertyList c = Encoding.toIEncoding (Encoding.multiMap (Encoding.ofIEncoding c))

static member enum<'t, 'u when 't : enum<'u> and 't : (new : unit -> 't) and 't : struct and 't :> ValueType> () : Codec<Encoding, 't> = Encoding.toIEncoding (Encoding.enumD <-> Encoding.enumE)

member x.getCase =
match x with
Expand Down
2 changes: 1 addition & 1 deletion src/Fleece.FSharpData/Fleece.FSharpData.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>JSON mapper for FSharp.Data</Description>
<DefineConstants>FSHARPDATA;$(DefineConstants)</DefineConstants>
Expand Down
66 changes: 33 additions & 33 deletions src/Fleece.NewtonsoftJson/Fleece.NewtonsoftJson.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ type [<Struct>] Encoding = Encoding of JsonValue with
| js -> Decode.Fail.numExpected (Encoding js)

/// Unwraps the JsonValue inside an IEncoding
static member Unwrap (x: IEncoding) = x :?> Encoding |> fun (Encoding s) -> s
static member Unwrap (Encoding s) = s

/// Wraps a JsonValue inside an IEncoding
static member Wrap x = Encoding x :> IEncoding
static member Wrap x = Encoding x

static member toIEncoding (c: Codec<JsonValue, 't>) : Codec<IEncoding, 't> = c |> Codec.compose ((Encoding.Unwrap >> Ok) <-> Encoding.Wrap)
static member ofIEncoding (c: Codec<IEncoding, 't>) : Codec<JsonValue, 't> = c |> Codec.compose ((Encoding.Wrap >> Ok) <-> Encoding.Unwrap)
static member toIEncoding (c: Codec<JsonValue, 't>) : Codec<Encoding, 't> = c |> Codec.compose ((Encoding.Unwrap >> Ok) <-> Encoding.Wrap)
static member ofIEncoding (c: Codec<Encoding, 't>) : Codec<JsonValue, 't> = c |> Codec.compose ((Encoding.Wrap >> Ok) <-> Encoding.Unwrap)

static member jsonObjectOfJson =
fun (o: JToken) ->
Expand Down Expand Up @@ -346,39 +346,39 @@ type [<Struct>] Encoding = Encoding of JsonValue with
static member guid = Encoding.guidD <-> Encoding.guidE


interface IEncoding with
member _.boolean = Encoding.toIEncoding Encoding.boolean
member _.string = Encoding.toIEncoding Encoding.string
member _.dateTime t =
interface IEncoding<Encoding> with
static member boolean = Encoding.toIEncoding Encoding.boolean
static member string = Encoding.toIEncoding Encoding.string
static member dateTime t =
match t with
| Some DateTimeContents.Date -> Encoding.toIEncoding Encoding.date
| Some DateTimeContents.Time -> Encoding.toIEncoding Encoding.time
| _ -> Encoding.toIEncoding Encoding.dateTime
member _.dateTimeOffset = Encoding.toIEncoding Encoding.dateTimeOffset
member _.timeSpan = Encoding.toIEncoding Encoding.timeSpan
member _.decimal = Encoding.toIEncoding Encoding.decimal
member _.float = Encoding.toIEncoding Encoding.float
member _.float32 = Encoding.toIEncoding Encoding.float32
member _.int = Encoding.toIEncoding Encoding.int
member _.uint32 = Encoding.toIEncoding Encoding.uint32
member _.int64 = Encoding.toIEncoding Encoding.int64
member _.uint64 = Encoding.toIEncoding Encoding.uint64
member _.int16 = Encoding.toIEncoding Encoding.int16
member _.uint16 = Encoding.toIEncoding Encoding.uint16
member _.byte = Encoding.toIEncoding Encoding.byte
member _.sbyte = Encoding.toIEncoding Encoding.sbyte
member _.char = Encoding.toIEncoding Encoding.char
member _.bigint = Encoding.toIEncoding Encoding.bigint
member _.guid = Encoding.toIEncoding Encoding.guid

member _.result c1 c2 = Encoding.toIEncoding (Encoding.result (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
member _.choice c1 c2 = Encoding.toIEncoding (Encoding.choice (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
member _.choice3 c1 c2 c3 = Encoding.toIEncoding (Encoding.choice3 (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2) (Encoding.ofIEncoding c3))
member _.option c = Encoding.toIEncoding (Encoding.option (Encoding.ofIEncoding c))
member _.array c = Encoding.toIEncoding (Encoding.array (Encoding.ofIEncoding c))
member _.propertyList c = Encoding.toIEncoding (Encoding.multiMap (Encoding.ofIEncoding c))

member _.enum<'t, 'u when 't : enum<'u> and 't : (new : unit -> 't) and 't : struct and 't :> ValueType> () : Codec<IEncoding, 't> = Encoding.toIEncoding (Encoding.enumD <-> Encoding.enumE)
static member dateTimeOffset = Encoding.toIEncoding Encoding.dateTimeOffset
static member timeSpan = Encoding.toIEncoding Encoding.timeSpan
static member decimal = Encoding.toIEncoding Encoding.decimal
static member float = Encoding.toIEncoding Encoding.float
static member float32 = Encoding.toIEncoding Encoding.float32
static member int = Encoding.toIEncoding Encoding.int
static member uint32 = Encoding.toIEncoding Encoding.uint32
static member int64 = Encoding.toIEncoding Encoding.int64
static member uint64 = Encoding.toIEncoding Encoding.uint64
static member int16 = Encoding.toIEncoding Encoding.int16
static member uint16 = Encoding.toIEncoding Encoding.uint16
static member byte = Encoding.toIEncoding Encoding.byte
static member sbyte = Encoding.toIEncoding Encoding.sbyte
static member char = Encoding.toIEncoding Encoding.char
static member bigint = Encoding.toIEncoding Encoding.bigint
static member guid = Encoding.toIEncoding Encoding.guid

static member result c1 c2 = Encoding.toIEncoding (Encoding.result (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
static member choice c1 c2 = Encoding.toIEncoding (Encoding.choice (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2))
static member choice3 c1 c2 c3 = Encoding.toIEncoding (Encoding.choice3 (Encoding.ofIEncoding c1) (Encoding.ofIEncoding c2) (Encoding.ofIEncoding c3))
static member option c = Encoding.toIEncoding (Encoding.option (Encoding.ofIEncoding c))
static member array c = Encoding.toIEncoding (Encoding.array (Encoding.ofIEncoding c))
static member propertyList c = Encoding.toIEncoding (Encoding.multiMap (Encoding.ofIEncoding c))

static member enum<'t, 'u when 't : enum<'u> and 't : (new : unit -> 't) and 't : struct and 't :> ValueType> () : Codec<Encoding, 't> = Encoding.toIEncoding (Encoding.enumD <-> Encoding.enumE)

member x.getCase =
match x with
Expand Down
2 changes: 1 addition & 1 deletion src/Fleece.NewtonsoftJson/Fleece.NewtonsoftJson.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>JSON mapper for Newtonsoft Json</Description>
<DefineConstants>NEWTONSOFT;$(DefineConstants)</DefineConstants>
Expand Down
Loading