Created
January 31, 2019 09:18
-
-
Save CapitanLiteral/192ebdfa506af905ebe18e23f5bd3c6f 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
using System.Collections.Generic; | |
using System.Linq; | |
public class EnumUtils<T> | |
{ | |
public static IEnumerable<T> GetAllValues() | |
{ | |
return System.Enum.GetValues(typeof(T)).Cast<T>(); | |
} | |
public static int GetNumberOfValues() | |
{ | |
return System.Enum.GetNames(typeof(T)).Length; | |
} | |
public static T ParseString(string inString) | |
{ | |
return (T)System.Enum.Parse(typeof(T), inString, true); | |
} | |
public static string ToString(T type) | |
{ | |
return System.Enum.GetName(typeof(T), type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment