Skip to content

Instantly share code, notes, and snippets.

@vshapenko
Created October 10, 2019 11:54
Show Gist options
  • Save vshapenko/8cd0c15d9e5c2f612da85b9d797d27fe to your computer and use it in GitHub Desktop.
Save vshapenko/8cd0c15d9e5c2f612da85b9d797d27fe to your computer and use it in GitHub Desktop.
|Shape.Enum s->
s.Accept {
new IEnumVisitor<Convert<'T>> with
member __.Visit<'t ,'u when 't : enum<'u>
and 't : struct
and 't :> ValueType
and 't : (new : unit -> 't)>() =
let printer=
fun x->
let ts:'u = unbox<'t> x|>LanguagePrimitives.EnumToValue
ts|>BsonValue
let parser=fun(v:BsonValue)->
let res:'t=LanguagePrimitives.EnumOfValue (unbox<'u> v.AsInt32)
res
mkParser printer parser
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment