So,
Just to be clear, I have already viewed this Q&A and this is not my question.
Now, my question is, I have a string that I'm able to extract from Excel and break it down by splitting and other methods and find whether it is an enum or not.
For example:
string enumStr = "eSomeEnumObject RANDOMENUMVAL"
is the string and I'm able to split and check if it is an enum and get a string array as such:
string[] enumArr = { "SomeEnumObject", "RANDOMENUMVAL" };
Now, I need to use it in a class TestClass
which references a library which contains various method definitions and enums as well.
The enum object name and value that I've just extracted basically already exists there. Now, I know that to convert a string to enum value we use something like this:
SomeEnumObject enumobj = (SomeEnumObject)Enum.Parse(typeof(SomeEnumObject, "RANDOMENUMVAL");
Now my question is:
How do I get this enum object name that I have as a string, be written as a enum object type, dynamically since I'm trying to automate the process, becuase obviously, when I try to write:
enumArr[0] enumobj = (enumArr[0])Enum.Parse(typeof(enumArr[0], enumArr[1]);
it will throw an error because it can't parse a string as an enum.
So now, is there a way to do this without re-defining the enum?
Thanks!