Advertisement
Guest User

Create union case from name

a guest
Aug 5th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.27 KB | None | 0 0
  1. open Microsoft.FSharp.Reflection
  2.  
  3. let makeUnionCase<'T>(name: string) =
  4.    let uci =
  5.        FSharpType.GetUnionCases(typeof<option<string>>)
  6.        |> Array.find (fun uci -> uci.Name = name)
  7.    Microsoft.FSharp.Reflection.FSharpValue.MakeUnion(uci, [||]) :?> 'T
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement