Skip to content

Commit e77f441

Browse files
committed
Add a .NET package
1 parent 5eff1f9 commit e77f441

21 files changed

+100
-21
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,24 @@ Why use codecs?
1010

1111
## Install
1212

13-
Install from [NuGet](https://www.nuget.org/packages/Thoth.Json.Codec/):
13+
Install from NuGet for [Fable](https://www.nuget.org/packages/Thoth.Json.Codec/) or [.NET](https://www.nuget.org/packages/Thoth.Json.Net.Codec/):
1414

1515
```bash
16+
# Fable
1617
dotnet add package Thoth.Json.Codec
18+
19+
# .NET
20+
dotnet add package Thoth.Json.Net.Codec
1721
```
1822

1923
Or using Paket:
2024

2125
```bash
26+
# Fable
2227
paket add Thoth.Json.Codec
28+
29+
# .NET
30+
paket add Thoth.Json.Net.Codec
2331
```
2432

2533
## Instructions
@@ -39,7 +47,11 @@ Remember that a well-formed codec will allow an arbitary number of encoding-deco
3947
First, open the namespace:
4048

4149
```fsharp
50+
#if FABLE_COMPILER
4251
open Thoth.Json.Codec
52+
#else
53+
open Thoth.Json.Net.Codec
54+
#endif
4355
```
4456

4557
Now you can create a codec from existing encoders and decoders like so:

paket.dependencies

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ source https://api.nuget.org/v3/index.json
22

33
storage: none
44
framework: net6.0, netstandard2.1
5-
nuget Expecto
6-
nuget Fable.Mocha
5+
76
nuget FSharp.Core >= 6
87
nuget Thoth.Json >= 7
9-
nuget Thoth.Json.Net >= 8
8+
nuget Thoth.Json.Net >= 8
9+
nuget Expecto
10+
nuget Fable.Mocha

tests/Auto.fs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module Thoth.Json.Codec.Tests.Auto
22

33
#if FABLE_COMPILER
4-
open Thoth.Json
54
open Fable.Mocha
5+
open Thoth.Json
6+
open Thoth.Json.Codec
67
#else
7-
open Thoth.Json.Net
88
open Expecto
9+
open Thoth.Json.Net
10+
open Thoth.Json.Net.Codec
911
#endif
1012

11-
open Thoth.Json.Codec
1213
open Thoth.Json.Codec.Tests.Utils
1314

1415
type Baz =

tests/Combinators.fs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ module Thoth.Json.Codec.Tests.Combinators
22

33
#if FABLE_COMPILER
44
open Fable.Mocha
5+
open Thoth.Json.Codec
56
#else
67
open Expecto
8+
open Thoth.Json.Net.Codec
79
#endif
810

9-
open Thoth.Json.Codec
1011
open Thoth.Json.Codec.Tests.Utils
1112

1213
let tests = testList "Combinators" [

tests/ObjectCodec.fs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ open System
44

55
#if FABLE_COMPILER
66
open Fable.Mocha
7+
open Thoth.Json.Codec
78
#else
89
open Expecto
10+
open Thoth.Json.Net.Codec
911
#endif
1012

11-
open Thoth.Json.Codec
1213
open Thoth.Json.Codec.Tests.Utils
1314

1415
type FooBar =

tests/Primitives.fs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ open System
44

55
#if FABLE_COMPILER
66
open Fable.Mocha
7+
open Thoth.Json.Codec
78
#else
89
open Expecto
10+
open Thoth.Json.Net.Codec
911
#endif
1012

11-
open Thoth.Json.Codec
1213
open Thoth.Json.Codec.Tests.Utils
1314

1415
let tests = testList "Primitives" [

tests/Utils.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module Thoth.Json.Codec.Tests.Utils
33
#if FABLE_COMPILER
44
open Fable.Mocha
55
open Thoth.Json
6+
open Thoth.Json.Codec
67
#else
7-
open Thoth.Json.Net
88
open Expecto
9+
open Thoth.Json.Net
10+
open Thoth.Json.Net.Codec
911
#endif
1012

11-
open Thoth.Json.Codec
12-
1313
let roundTrip (codec : Codec<'t>) v =
1414
let encoded =
1515
v

tests/VariantCodec.fs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ module Thoth.Json.Codec.Tests.Variant
22

33
#if FABLE_COMPILER
44
open Fable.Mocha
5+
open Thoth.Json
6+
open Thoth.Json.Codec
57
#else
68
open Expecto
9+
open Thoth.Json.Net
10+
open Thoth.Json.Net.Codec
711
#endif
812

9-
open Thoth.Json.Codec
1013
open Thoth.Json.Codec.Tests.Utils
1114

1215
type Shape =

tests/tests.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<Compile Include="Program.fs" />
1515
</ItemGroup>
1616
<ItemGroup>
17+
<ProjectReference Include="..\thoth-json-net-codec\thoth-json-net-codec.fsproj" />
1718
<ProjectReference Include="..\thoth-json-codec\thoth-json-codec.fsproj" />
1819
</ItemGroup>
1920
<Import Project="..\.paket\Paket.Restore.targets" />

thoth-json-codec.sln

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30114.105
55
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "thoth-json-net-codec", "thoth-json-net-codec\thoth-json-net-codec.fsproj", "{723F332D-86B5-4853-AAB9-905E7B07C205}"
7+
EndProject
68
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "thoth-json-codec", "thoth-json-codec\thoth-json-codec.fsproj", "{4BFD6727-BAAD-44FD-B7FD-CE3B91120199}"
79
EndProject
810
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "tests", "tests\tests.fsproj", "{057883BA-B226-4326-94F4-3918E245651B}"
@@ -24,5 +26,9 @@ Global
2426
{057883BA-B226-4326-94F4-3918E245651B}.Debug|Any CPU.Build.0 = Debug|Any CPU
2527
{057883BA-B226-4326-94F4-3918E245651B}.Release|Any CPU.ActiveCfg = Release|Any CPU
2628
{057883BA-B226-4326-94F4-3918E245651B}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{723F332D-86B5-4853-AAB9-905E7B07C205}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{723F332D-86B5-4853-AAB9-905E7B07C205}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{723F332D-86B5-4853-AAB9-905E7B07C205}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{723F332D-86B5-4853-AAB9-905E7B07C205}.Release|Any CPU.Build.0 = Release|Any CPU
2733
EndGlobalSection
2834
EndGlobal

thoth-json-codec/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# thoth-json-code
2+
3+
Fable compatible version of the library.

thoth-json-codec/paket.references

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
FSharp.Core
22
Thoth.Json
3-
Thoth.Json.Net

thoth-json-codec/thoth-json-codec.fsproj

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
<DefineConstants>$(DefineConstants);FABLE_COMPILER</DefineConstants>
67
</PropertyGroup>
78
<ItemGroup>
8-
<Compile Include="Codec.fs" />
9-
<Compile Include="Object.fs" />
10-
<Compile Include="Variant.fs" />
11-
<Compile Include="Auto.fs" />
9+
<Compile Include="../thoth-json-net-codec/Codec.fs" />
10+
<Compile Include="../thoth-json-net-codec/Object.fs" />
11+
<Compile Include="../thoth-json-net-codec/Variant.fs" />
12+
<Compile Include="../thoth-json-net-codec/Auto.fs" />
1213
</ItemGroup>
1314
<ItemGroup>
1415
<Content Include="*.fsproj; **\*.fs; **\*.fsi" PackagePath="fable\" />

thoth-json-codec/Auto.fs thoth-json-net-codec/Auto.fs

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if FABLE_COMPILER
12
namespace Thoth.Json.Codec
3+
#else
4+
namespace Thoth.Json.Net.Codec
5+
#endif
26

37
#if FABLE_COMPILER
48
open Thoth.Json

thoth-json-codec/Codec.fs thoth-json-net-codec/Codec.fs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
namespace Thoth.Json.Codec
1+
#if FABLE_COMPILER
2+
namespace Thoth.Json.Codec
3+
#else
4+
namespace Thoth.Json.Net.Codec
5+
#endif
26

37
open System
48

thoth-json-codec/Object.fs thoth-json-net-codec/Object.fs

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if FABLE_COMPILER
12
namespace Thoth.Json.Codec
3+
#else
4+
namespace Thoth.Json.Net.Codec
5+
#endif
26

37
#if FABLE_COMPILER
48
open Thoth.Json

thoth-json-net-codec/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# thoth-json-code-net
2+
3+
.NET compatible version of the library.

thoth-json-codec/Variant.fs thoth-json-net-codec/Variant.fs

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if FABLE_COMPILER
12
namespace Thoth.Json.Codec
3+
#else
4+
namespace Thoth.Json.Net.Codec
5+
#endif
26

37
#if FABLE_COMPILER
48
open Thoth.Json

thoth-json-net-codec/paket.references

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FSharp.Core
2+
Thoth.Json.Net
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="Codec.fs" />
9+
<Compile Include="Object.fs" />
10+
<Compile Include="Variant.fs" />
11+
<Compile Include="Auto.fs" />
12+
</ItemGroup>
13+
<Import Project="..\.paket\Paket.Restore.targets" />
14+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type project
2+
id Thoth.Json.Net.Codec
3+
version 0.0.1
4+
authors github.com/njlr
5+
title Thoth.Json.Net.Codec
6+
tags fable fsharp json thoth codec
7+
repositoryType git
8+
repositoryUrl https://github.com/njlr/thoth-json-codec
9+
files
10+
../LICENSE.txt ==> LICENSE.txt
11+
description Codec support for Thoth.Json.Net
12+
summary Codec support for Thoth.Json.Net
13+
licenseUrl https://licenses.nuget.org/MIT
14+
licenseExpression MIT

0 commit comments

Comments
 (0)