A possibly simpler version of this is to create an extension method for
public static class MyExtensions
public static TEnum ParseEnum<TEnum>(this string value,
bool ignoreCase = false) where TEnum : struct
Enum.TryParse<TEnum>(value, ignoreCase, out tenumResult);
Note that you also do not need to assign or return
will always set
for you, regardless of success or failure when parsing.
var enumValue = "One".ParseEnum<EnumOne>();
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.