Skip to content

Instantly share code, notes, and snippets.

@jinwoo-lee-github
Created February 20, 2015 03:12
Show Gist options
  • Save jinwoo-lee-github/f822de26a807849167fc to your computer and use it in GitHub Desktop.
Save jinwoo-lee-github/f822de26a807849167fc to your computer and use it in GitHub Desktop.
convert string to enum
public class ATUtil
{
static public T GetEnum<T>(string name, T defaultValue)
{
string[] names = System.Enum.GetNames(typeof(T));
System.Array values = System.Enum.GetValues(typeof(T));
for (int i = 0; i < names.Length; ++i)
{
if (names[i] == name)
return (T)values.GetValue(i);
}
return defaultValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment