Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Last active August 29, 2015 14:20
Show Gist options
  • Save SteveGilham/1a749242f0e541126704 to your computer and use it in GitHub Desktop.
Save SteveGilham/1a749242f0e541126704 to your computer and use it in GitHub Desktop.
Get Union types -- generalised
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