I want to convert string representations from dozens of enumeration types to enumeration values. It is easy to convert a string to a specific type:
Enum.Parse(typeof<FontStyle>,"Bold") |> unbox<FontStyle>
but for now I want to write a function where type and string are parameters. The best I can write is:
> let s2e (_: 'a) s = Enum.Parse(typeof<'a>,s) |> unbox<'a>;;
val s2e : 'a -> string -> 'a
> s2e FontStyle.Regular "Bold";;
val it : FontStyle = Bold
Is there a way to write something like this, but with the type itself as the first argument?
source
share