jeudi 12 janvier 2017

F#: Attributes on discriminated union fields?

I can do this:

type AttrAttribute () =
    inherit Attribute ()

type MyDU =
    | [<Attr>]A of bool
    | [<Attr>]B of int * string
    | [<Attr>]C of byte * char * int64

... but is there any way to do this?

type MyDU =
    | A of [<Attr>]bool
    | B of int * [<Attr>]string
    | C of [<Attr>]byte * char * [<Attr>]int64

Apparently, the case values are just fields (e.g. let v = B (13, "oops") in (Microsoft.FSharp.Reflection.FSharpValue.GetUnionFields (v, v.GetType ()) |> fst).GetFields ()), so I'm hoping this is doable, somehow.





Aucun commentaire:

Enregistrer un commentaire