I read the answers of those questions:
- Generic F# function: How to get the Type of an F# Discriminated Union?
- C# types for empty F# discriminated union cases
- (mine) How to get the type of each union case for a given union type in F#
But I found out something surprising about the underlying type of discriminated unions:
type Union1 =
| A
| B
type Union2 =
| A
| B of int
[<EntryPoint>]
let main argv =
printfn "%A" (Union1.A.GetType())
printfn "%A" (Union1.B.GetType())
printfn "%A" (Union2.A.GetType())
printfn "%A" (Union2.B(32).GetType())
0
Program+Union1
Program+Union1
Program+Union2+_A
Program+Union2+B
Hence my question how I can discriminate a case based on the type when a case is empty?
Aucun commentaire:
Enregistrer un commentaire