-
-
Save danzel/ffb71b533083f7c5f728 to your computer and use it in GitHub Desktop.
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 T ReadEnum<T>(string tok) where T : struct | |
{ | |
if(typeof(T).IsEnum == false) | |
{ | |
throw new Exception("Generic type " + typeof(T).Name + " passed to ReadEnum<T> is not an enum type"); | |
} | |
T toReturn = default(T); | |
try | |
{ | |
toReturn = (T)Enum.Parse(typeof(T), tok); | |
} | |
catch (Exception e) | |
{ | |
Debug.LogWarning("String " + tok + " is not a valid type in enum " + typeof(T).Name + ", returning default value"); | |
} | |
return toReturn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment