G
Guest
In a posting earlier this year I found a simple approach to convert a string
to a particular Enum value. The one line solution looked like this:
MyEnum ConvertedString = (MyEnum) Enum.Parse(typeof(MyEnum), MyString, true);
This is fine if one wants to hardcode each and every Enum in an If-ElseIf or
Select-Case construct but I'm wondering if there's a way to do it generically?
I have a situation where I'm using reflection to set a value. Here is the
code I've successfully been using:
propInfo.SetValue(node.Obj, Convert.ChangeType(newval,
propInfo.PropertyType, null), indexer);
This has worked perfectly for the basic user types (ex. string, bool, int,
etc.) but fails if I try to introduce a property that is defined with a type
of one of my Enums.
Any ideas?
to a particular Enum value. The one line solution looked like this:
MyEnum ConvertedString = (MyEnum) Enum.Parse(typeof(MyEnum), MyString, true);
This is fine if one wants to hardcode each and every Enum in an If-ElseIf or
Select-Case construct but I'm wondering if there's a way to do it generically?
I have a situation where I'm using reflection to set a value. Here is the
code I've successfully been using:
propInfo.SetValue(node.Obj, Convert.ChangeType(newval,
propInfo.PropertyType, null), indexer);
This has worked perfectly for the basic user types (ex. string, bool, int,
etc.) but fails if I try to introduce a property that is defined with a type
of one of my Enums.
Any ideas?