Created
February 20, 2015 03:12
-
-
Save jinwoo-lee-github/f822de26a807849167fc to your computer and use it in GitHub Desktop.
convert string to enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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