Allow serde of guids (#82)

This commit is contained in:
Patrick Stevens
2024-02-06 18:50:26 +00:00
committed by GitHub
parent e453a6f07c
commit 1215834795
6 changed files with 42 additions and 5 deletions

View File

@@ -467,6 +467,15 @@ module internal SynTypePatterns =
| _ -> None
| _ -> None
let (|Guid|_|) (fieldType : SynType) : unit option =
match fieldType with
| SynType.LongIdent ident ->
match ident.LongIdent |> List.map (fun i -> i.idText) with
| [ "System" ; "Guid" ]
| [ "Guid" ] -> Some ()
| _ -> None
| _ -> None
let (|HttpResponseMessage|_|) (fieldType : SynType) : unit option =
match fieldType with
| SynType.LongIdent ident ->

View File

@@ -211,6 +211,12 @@ module internal JsonParseGenerator =
node
|> asValueGetValue propertyName "string"
|> SynExpr.pipeThroughFunction (SynExpr.CreateLongIdent (SynLongIdent.Create [ "System" ; "Uri" ]))
| Guid ->
node
|> asValueGetValue propertyName "string"
|> SynExpr.pipeThroughFunction (
SynExpr.CreateLongIdent (SynLongIdent.Create [ "System" ; "Guid" ; "Parse" ])
)
| DateTime ->
node
|> asValueGetValue propertyName "string"

View File

@@ -43,8 +43,9 @@ module internal JsonSerializeGenerator =
| DateTime
| NumberType _
| PrimitiveType _
| Guid
| Uri ->
// JsonValue.Create<{type}>
// JsonValue.Create<type>
SynExpr.TypeApp (
SynExpr.CreateLongIdent (
SynLongIdent.Create [ "System" ; "Text" ; "Json" ; "Nodes" ; "JsonValue" ; "Create" ]