Is there a cleaner, more clever way to do this?
I’m hitting a DB to get data to fill an object and am converting a database string value back into its enum (we can assume that all values in the database are indeed values in the matching enum)
The line in question is the line below that sets EventLog.ActionType…the reason I began to question my method is because after the equals sign, VS2010 keeps trying to override what I’m typing by putting this: “= EventActionType(”
using (..<snip>..)
{
while (reader.Read())
{
// <snip>
eventLog.ActionType = (EventActionType)Enum.Parse(typeof(EventActionType), reader[3].ToString());
...etc...
As far as I know, this is the best way to do it. I’ve set up a utility class to wrap this functionality with methods that make this look cleaner, though.
With these utility methods, you can just say: