I\'m trying to create DU cases from strings. The only way I can see doing this is by enumerating over the DU cases via Microsoft.FSharp.Reflection.FSharpType.GetUnionC
Microsoft.FSharp.Reflection.FSharpType.GetUnionC
As the cases have no value, another option is to use enums:
type Keyword = | FOO = 0 | BAR = 1 | BAZ = 2 | BLAH = 3 let strings = ["FOO";"BAR"] let keywords = [for s in strings -> s, Keyword.Parse(typeof, s)] |> Map.ofList
Then you can simply use Enum.Parse.