Created
February 13, 2017 07:38
-
-
Save x5lcfd/047cbbbbc79d9e907fd656df2aa5d9f3 to your computer and use it in GitHub Desktop.
StringToEnum
This file contains hidden or 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
// Mono2.6 doesn't have Enum.TryParse | |
public static TEnum ToEnum<TEnum>(this string strEnumValue, TEnum defaultValue) | |
{ | |
if (!Enum.IsDefined(typeof(TEnum), strEnumValue)) | |
return defaultValue; | |
return (TEnum)Enum.Parse(typeof(TEnum), strEnumValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment