On Wednesday, 27 May 2020 at 17:33:33 UTC, Vinod K Chandran wrote:
Hi all,
Assume that i have an enum like this.
enum TestEnum {
Received = 1,
Started ,
Finished ,
Sent
}
I am saving this enum values as string in database. So, when i
retrieve them from the database, how can i parse the string
into TestEnum ? In vb. net, i can use
[Enum].Parse(GetType( TestEnum), "Started")
How to do this in D ?
Parsing enum from a string can be done using the Enum.Parse()
method. First, the enum type is passed into the method as a
parameter. Then, the string to be parsed is passed in as the
second parameter. If the string cannot be parsed into the enum
type, then a exception will be thrown. To avoid this, the
TryParse() method can be used instead, which will return a
boolean value.
https://andersenlab.com/blueprint/choosing-the-best-test-automation-frameworks