Skip to content

Instantly share code, notes, and snippets.

@jandk
Created November 21, 2013 11:36
Show Gist options
  • Save jandk/7580109 to your computer and use it in GitHub Desktop.
Save jandk/7580109 to your computer and use it in GitHub Desktop.
static T Parse<T>(string value)
where T : struct
{
var type = typeof(T);
if (!type.IsEnum)
throw new ArgumentException("T is not an enum");
var enumValue = Enum.Parse(type, value);
return (T)enumValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment