Last active
August 29, 2015 14:20
-
-
Save SteveGilham/1a749242f0e541126704 to your computer and use it in GitHub Desktop.
Get Union types -- generalised
This file contains hidden or 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
let GetUnionTypes (t:Type) = | |
seq { yield t | |
if FSharpType.IsUnion t | |
then yield! FSharpType.GetUnionCases t | |
// implementation detail leaks here -- nested type name | |
|> Seq.map (fun x -> Type.GetType ((string t) + "+" + x.Name)) | |
// except when the case has no data, so there's no such class | |
|> Seq.filter (fun x -> x <> null) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment