-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added requireRecordFields option to Newtonsoft.Json
- Loading branch information
1 parent
8f765f7
commit 3097d9a
Showing
7 changed files
with
117 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module internal Internal | ||
|
||
open TypeShape.Core | ||
|
||
let checkIfSupported<'Contract> requireRecordFields = | ||
if not requireRecordFields then | ||
let shape = | ||
match shapeof<'Contract> with | ||
| Shape.FSharpUnion (:? ShapeFSharpUnion<'Contract> as s) -> s | ||
| _ -> | ||
sprintf "Type '%O' is not an F# union" typeof<'Contract> | ||
|> invalidArg "Union" | ||
let isAllowed (scase : ShapeFSharpUnionCase<_>) = | ||
match scase.Fields with | ||
| [| field |] -> | ||
match field.Member with | ||
// non-primitives | ||
| Shape.FSharpRecord _ | ||
| Shape.Guid _ | ||
|
||
// primitives | ||
| Shape.Bool _ | ||
| Shape.Byte _ | ||
| Shape.SByte _ | ||
| Shape.Int16 _ | ||
| Shape.Int32 _ | ||
| Shape.Int64 _ | ||
//| Shape.IntPtr _ // unsupported | ||
| Shape.UInt16 _ | ||
| Shape.UInt32 _ | ||
| Shape.UInt64 _ | ||
//| Shape.UIntPtr _ // unsupported | ||
| Shape.Single _ | ||
| Shape.Double _ | ||
| Shape.Char _ -> true | ||
| _ -> false | ||
| [||] -> true // allows all nullary cases, but a subsequent check is done by UnionContractEncoder.Create with `allowNullaryCases` | ||
| _ -> false | ||
shape.UnionCases | ||
|> Array.tryFind (not << isAllowed) | ||
|> function | ||
| None -> () | ||
| Some x -> failwithf "The '%s' case has an unsupported type: '%s'" x.CaseInfo.Name x.Fields.[0].Member.Type.FullName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters