In Fsharp you can convert string to enum link follows:
type Langs =
| En = 0
| Afr = 1
let tryLang str =
try
Enum.Parse(typedefof<Langs>, str) :?> Langs
with e ->
Langs.En
In fable I get the following error:
error FABLE: Cannot resolve System.Enum.Parse
Is there a way to do the conversion without having to use a match statement or some other lookup?
Thanks
The short answer is: No, fable cannot do this.
Fable can compile most of F#, but very little of .Net BCL (Base Class Library).
You might, however, be interested in StringEnum attribute to solve your particular problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With